Some Dude
/
Shift_brite
A simple program to cycle a chain of shiftbrites through RGB,MCY,W using mbed.
main.cpp
- Committer:
- bh27
- Date:
- 2011-03-17
- Revision:
- 0:0992b23a3b05
- Child:
- 1:8e28c267ff1a
File content as of revision 0:0992b23a3b05:
// 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); } }