Some Dude
/
Shift_brite
A simple program to cycle a chain of shiftbrites through RGB,MCY,W using mbed.
Revision 0:0992b23a3b05, committed 2011-03-17
- Comitter:
- bh27
- Date:
- Thu Mar 17 11:22:39 2011 +0000
- Child:
- 1:8e28c267ff1a
- Commit message:
- 1.0
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 17 11:22:39 2011 +0000 @@ -0,0 +1,136 @@ +// A simple program to cycle a chain of shiftbrites through RGB,MCY,W using mbed. + +// Shift register code from: http://mbed.org/users/ChriX/notebook/shift-register-function/ +// Shiftbrite Arduino code from: http://macetech.com/blog/node/54 + +#include "mbed.h" + +DigitalOut datapin(p30); +DigitalOut latchpin(p29); +DigitalOut enablepin(p28); +DigitalOut clockpin(p27); + +unsigned long SB_CommandPacket; +int SB_CommandMode; +int SB_BlueCommand; +int SB_RedCommand; +int SB_GreenCommand; +int No_of_shiftbrites = 4; + +void shiftOut(DigitalOut data, DigitalOut clk, int sodata) { + + int i; + + for (i = 7; i >= 0; i--) { + + clk = 0; + + if(sodata & (1 << i)){ + data = 1; + } else { + data = 0; + } + + clk = 1; + data = 0; + } + +return; + +} + + +void SB_SendPacket() { + + for (int y = No_of_shiftbrites-1; y >= 0; y--) { + SB_CommandPacket = SB_CommandMode & 0xB11; + SB_CommandPacket = (SB_CommandPacket << 10) | (SB_BlueCommand & 1023); + SB_CommandPacket = (SB_CommandPacket << 10) | (SB_RedCommand & 1023); + SB_CommandPacket = (SB_CommandPacket << 10) | (SB_GreenCommand & 1023); + + shiftOut(datapin, clockpin, SB_CommandPacket >> 24); + shiftOut(datapin, clockpin, SB_CommandPacket >> 16); + shiftOut(datapin, clockpin, SB_CommandPacket >> 8); + shiftOut(datapin, clockpin, SB_CommandPacket); + + + wait_us(500); + latchpin = 1; + wait_us(500); + latchpin = 0; + } + +} + +int main() { + while(1) { + SB_CommandMode = 0xB01; + SB_RedCommand = 127; + SB_GreenCommand = 127; + SB_BlueCommand = 127; + SB_SendPacket(); + + // Red + SB_CommandMode = 0xB00; + SB_RedCommand = 127; // max = 1023 + SB_GreenCommand = 0; + SB_BlueCommand = 0; + SB_SendPacket(); + + wait_ms(500); + + // Green + SB_CommandMode = 0xB00; + SB_RedCommand = 0; + SB_GreenCommand = 127; + SB_BlueCommand = 0; + SB_SendPacket(); + + wait_ms(500); + + // Blue + SB_CommandMode = 0xB00; + SB_RedCommand = 0; + SB_GreenCommand = 0; + SB_BlueCommand = 127; + SB_SendPacket(); + + wait_ms(500); + + // Magenta + SB_CommandMode = 0xB00; + SB_RedCommand = 127; + SB_GreenCommand = 0; + SB_BlueCommand = 127; + SB_SendPacket(); + + wait_ms(500); + + // Cyan + SB_CommandMode = 0xB00; + SB_RedCommand = 0; + SB_GreenCommand = 127; + SB_BlueCommand = 127; + SB_SendPacket(); + + wait_ms(500); + + // Yellow + SB_CommandMode = 0xB00; + SB_RedCommand = 127; + SB_GreenCommand = 127; + SB_BlueCommand = 0; + SB_SendPacket(); + + wait_ms(500); + + // White + SB_CommandMode = 0xB00; + SB_RedCommand = 127; + SB_GreenCommand = 127; + SB_BlueCommand = 127; + SB_SendPacket(); + + wait_ms(500); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Mar 17 11:22:39 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912