Driver for the GE Color Effects LED lights. Currently it is blocking, but it could be made to be nonblocking.
Dependents: GEColorEffects_Example GEColorEffects_Example
This library's code is based on Clark Jarvis's program here: http://developer.mbed.org/users/clarkjarvis/code/FRDM_GE_ColorEffects/
Diff: GEColorEffects.cpp
- Revision:
- 0:3f51641c4e69
- Child:
- 1:e56bc0a8c273
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GEColorEffects.cpp Mon Feb 16 20:27:53 2015 +0000 @@ -0,0 +1,75 @@ +#include "GEColorEffects.h" + +GEColorEffects::GEColorEffects(PinName pin, int size) : size(size), gpo(pin) { + +} + + +void GEColorEffects::write(int buf[], bool eightBit) { + int l, r, g, b; + for (int i = 0; i < size; i++) { + l = (buf[i] >> 24) & 0xFF; + r = (buf[i] >> 16) & 0xFF; + g = (buf[i] >> 8) & 0xFF; + b = buf[i] & 0xFF; + + if (eightBit) { + sendFrame(i, l, r >> 4, g >> 4, b >> 4); + } else { + sendFrame(i, l, r, g, b); + } + } +} + +// GPIO output to send a logical 0 +void GEColorEffects::sendZero() { + gpo = 0; + wait_us(10); + gpo = 1; + wait_us(20); +} + +// GPIO output to send a logical 1 +void GEColorEffects::sendOne() { + gpo = 0; + wait_us(20); + gpo = 1; + wait_us(10); +} + +// Parse data value to serial process 0/1's +void GEColorEffects::sendData(unsigned char data, int length) { + unsigned int data_bit; + + for (int i = (length - 1); i >= 0; i--) { + data_bit = (data >> i) & 0x01; + if (data_bit == 0) { + sendZero(); + } else { + sendOne(); + } + } +} + +// Send frame of data to control a single pixel +void GEColorEffects::sendFrame(unsigned char address, unsigned char lumm, unsigned char R, unsigned char G, unsigned char B) { +// Send "1" value to start Frame + sendOne(); +// Send Address + sendData(address,6); +// Send Luminosity + sendData(lumm,8); +// Send Blue 4-bits + sendData(B,4); +// Send Green 4-bits + sendData(G,4); +// Send Red 4-bits + sendData(R,4); +// Send End of Frame Marker + endFrame(); +} + +void GEColorEffects::endFrame() { + gpo = 0; + wait_us(30); +} \ No newline at end of file