Click here to Skip to main content
15,892,059 members
Articles / Internet of Things / Arduino

Simulating and controlling GE Color Effects Lights with Arduino

Rate me:
Please Sign up or sign in to vote.
4.80/5 (13 votes)
27 Nov 2012CPOL13 min read 137.9K   1.4K   25  
Simulating and Controlling GE Color Effects Lights with Arduino
#ifndef _GLOBAL_H
#define _GLOBAL_H

// this is the maximum number of strings we can support ... valid values are 1 ... 8 ... only reason to reduce it would be to try to save a tiny bit of memory
#define MAXSTRINGS 8

// If set to 1 a pattern of color flashes shows on initialisation
#define STARTPATTERN 1

// There are 3 potential target platforms
//
// Win32 - To target this platform make sure PC is #defined or passed to the compiler. RASPBERRY must not also be defined.
// Raspberry Pi - To target this platform make sure RASPBERRY is #defined or passed to the compiler. PC must not also be defined.
// Arduino Pro - To target this platform make sure PC, RASPBERRY and BOARD2560 are not defined
// Arduino Mega 2560 - To target this platform make sure PC and RASPBERRY are not defined and BOARD2560 is defined
//
// There are some key #defines which will control the way the program works
//
// USWAITSINGLE - This is the microseconds to wait between sending data pulses when sending instructions to one bulb on one string
// MICROSECONDSWAITPARALLEL - This is the microseconds to wait between sending data pulses when sending instructions to 1 bulb on every string at once
// PARALLELDISPLAY - Use this if you want the program to send data to all strings at once. If it is not defined then each bulb is sent separately. Parallel is faster.
// SENDTOEMULATOR - Use this to have the program send the instructions to the emulator as well over TCP/IP (PC/RASPBERRY) or Serial (ARDUINO). This slows down the program but lets you see what it is trying to do. You pretty much have to turn this on when compiling for the PC as that is the only reason you would compile it for the PC. IF you only want to send messages use SENDTOEMULATORMSGS instead.
// SENDTOEMULATORMSGS - Use this to have the program send the trace messages to the emulator as well over TCP/IP (PC/RASPBERRY) or Serial (ARDUINO). This slows down the program but lets you see the trace messages
// USEDELAYUNTIL - This switch enables some Raspberry specific timing that tries to time pulses by comparing the time back to the start of sending the current bit stream. Current testing suggests this does not work well
// DOYIELD - This switch forces the RASPBERRY to yield just before sending a bit pattern in the hope this makes it less likely to be pre-empted during transmission. Current testing suggests this does not help much
// USEPORTL - This switch forces the Arduino Mega to use output pins 49-42 instead of 2-9 - because these map directly to a single PORTL instruction it is faster
// MINMEMORY - This switch foreces the debug messages to be briefer and not to include data fields but they occupy a lot less memory. On the Arduino Pro this is quite important especially if you program is large
// INCLUDE_PARAM_CHECK - This switch turns on additional parameter validation logic which is really only required during development of my code
// INCLUDE_MSG_* - These switches turn on levels of debug messaging
// FASTPARALLELDISPLAY - This switches on some fancier and theoretically faster parallel display logic which allows the parallel display to write to different numbered bulbs on different strings
// USEINTERRUPT - Used by raspberry to use interupt detection to decide if a time has elapsed rather than continually getting the time

#ifdef PC
	#define MICROSECONDSWAITPARALLEL 0
	#define USWAITSINGLE 0
	#define PARALLELDISPLAY 1
	#define SENDTOEMULATOR 1
	#define SENDTOEMULATORMSGS 1
	#define FASTPARALLELDISPLAY 1
#elif defined(RASPBERRY)
	#define MICROSECONDSWAITPARALLEL 9
	#define USWAITSINGLE 10
	#define PARALLELDISPLAY 1
	//#define USEDELAYUNTIL 1
	//#define SENDTOEMULATOR 1
	//#define SENDTOEMULATORMSGS 1
	#define DOYIELD 1
	#define FASTPARALLELDISPLAY 1
	#define USEINTERRUPT 1
#else
	#define USEARDUINO 1
	#define BOARD2560 1

	#ifdef BOARD2560
		//#define PARALLELDISPLAY 1
		#define USEPORTL // this should be faster
		#define USWAITSINGLE 0
		#define MICROSECONDSWAITPARALLEL 7
		//#define SENDTOEMULATOR 1
		//#define SENDTOEMULATORMSGS 1
		#define MINMEMORY 1
		#define FASTPARALLELDISPLAY 1
		#define INCLUDE_DEBUG_PATTERNS 1
	#else
		#define MINMEMORY 1
		#define USWAITSINGLE 0
		#define MICROSECONDSWAITPARALLEL 0
		//#define SENDTOEMULATOR 1
		//#define SENDTOEMULATORMSGS 1
		#define PARALLELDISPLAY 1
		#define FASTPARALLELDISPLAY 1
	#endif
#endif

// If this is set then on machines with memory limitations some optional processing will be excluded
#if defined(PC) || defined(RASPBERRY)
	#define INCLUDE_MSG_CRITICAL 1
	#define INCLUDE_MSG_IMPORTANT 1
	#define INCLUDE_MSG_SUMMARY 1
	#define INCLUDE_MSG_DETAIL 1
	//#define INCLUDE_MSG_SUPERDETAIL 1
	#define INCLUDE_PARAM_CHECK 1
#else
	//#define INCLUDE_MSG_CRITICAL 1
	//#define INCLUDE_MSG_IMPORTANT 1
	//#define INCLUDE_MSG_SUMMARY 1
	//#define INCLUDE_MSG_DETAIL 1
	//#define INCLUDE_MSG_SUPERDETAIL 1
	//#define INCLUDE_PARAM_CHECK 1
#endif

#ifdef RASPBERRY
	#define byte unsigned char
	#include <string.h>
	#include <sched.h>
	#define DONT_FAIL_ON_HARDWARE_ERRORS
#endif

#if defined(PC) || defined(RASPBERRY)
	#include <stdio.h>
#else
	// include necessary header for libraries.
	#if defined(ARDUINO) && ARDUINO >= 100
		#include "Arduino.h"
	#else
		#include "WProgram.h"
	#endif
	#include <avr/pgmspace.h>
#endif

#include "Platform.h"
#include "cppfix.h"

#endif // _GLOBAL_H

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions