Skip to content
Browse files

Adding pre-existing code

  • Loading branch information...
1 parent 44fdbac commit fc694714badfa58a6a1134d98cd1cad9b1d10087 @pvince pvince committed Jan 18, 2011
View
154 WindowFrames/WindowFrames.pde
@@ -0,0 +1,154 @@
+#include <avr/pgmspace.h>
+
+#define clockpin 13 // CI
+#define enablepin 10 // EI
+#define latchpin 9 // LI
+#define datapin 11 // DI
+
+#define NumLEDs 56
+
+#define rows 8
+#define columns 7
+
+int LEDChannels[NumLEDs][3] = {0};
+int SB_CommandMode;
+int SB_RedCommand;
+int SB_GreenCommand;
+int SB_BlueCommand;
+
+int current_img[columns][rows][3] = {0};
+int next_img[columns][rows][3] = {0};
+
+int num_frames = 2;
+int current_frame = 0;
+
+PROGMEM prog_int16_t all_white[columns][rows][3] = {
+ { { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } },
+ { { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } },
+ { { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } },
+ { { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } },
+ { { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } },
+ { { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } },
+ { { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } }
+};
+
+PROGMEM prog_int16_t hive_logo[columns][rows][3] = {
+ { { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } },
+ { { 1000, 1000, 1000 } , { 0, 1000, 0 } , { 0, 1000, 0 } , { 0, 1000, 0 } , { 0, 1000, 0 } , { 0, 1000, 0 } , { 0, 1000, 0 } , { 1000, 1000, 1000 } },
+ { { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 0, 1000, 0 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } },
+ { { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 0, 1000, 0 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } },
+ { { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 0, 1000, 0 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } },
+ { { 1000, 1000, 1000 } , { 0, 1000, 0 } , { 0, 1000, 0 } , { 0, 1000, 0 } , { 0, 1000, 0 } , { 0, 1000, 0 } , { 0, 1000, 0 } , { 1000, 1000, 1000 } },
+ { { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } , { 1000, 1000, 1000 } }
+};
+
+
+void setup() {
+
+ pinMode(datapin, OUTPUT);
+ pinMode(latchpin, OUTPUT);
+ pinMode(enablepin, OUTPUT);
+ pinMode(clockpin, OUTPUT);
+ SPCR = (1<<SPE)|(1<<MSTR)|(0<<SPR1)|(0<<SPR0);
+ digitalWrite(latchpin, LOW);
+ digitalWrite(enablepin, LOW);
+
+}
+
+
+void SB_SendPacket() {
+
+ if (SB_CommandMode == B01) {
+ SB_RedCommand = 65;
+ SB_GreenCommand = 50;
+ SB_BlueCommand = 50;
+ }
+
+ SPDR = SB_CommandMode << 6 | SB_BlueCommand>>4;
+ while(!(SPSR & (1<<SPIF)));
+ SPDR = SB_BlueCommand<<4 | SB_RedCommand>>6;
+ while(!(SPSR & (1<<SPIF)));
+ SPDR = SB_RedCommand << 2 | SB_GreenCommand>>8;
+ while(!(SPSR & (1<<SPIF)));
+ SPDR = SB_GreenCommand;
+ while(!(SPSR & (1<<SPIF)));
+
+}
+
+void WriteLEDArray() {
+
+ SB_CommandMode = B00; // Write to PWM control registers
+ for (int h = 0;h<NumLEDs;h++) {
+ SB_RedCommand = LEDChannels[h][0];
+ SB_GreenCommand = LEDChannels[h][1];
+ SB_BlueCommand = LEDChannels[h][2];
+ SB_SendPacket();
+ }
+
+ delayMicroseconds(15);
+ digitalWrite(latchpin,HIGH); // latch data into registers
+ delayMicroseconds(15);
+ digitalWrite(latchpin,LOW);
+
+ SB_CommandMode = B01; // Write to current control registers
+ for (int z = 0; z < NumLEDs; z++) SB_SendPacket();
+ delayMicroseconds(15);
+ digitalWrite(latchpin,HIGH); // latch data into registers
+ delayMicroseconds(15);
+ digitalWrite(latchpin,LOW);
+
+}
+
+void ConvertImg(){
+ //converts the "2D" current_img array into the "1D" LEDChannels array
+
+ for ( int x = 0; x < columns; x++ ){
+ for ( int y = 0; y < rows; y++ ){
+
+ int h = 0;
+ //the following deals with the alternating direction of the rows
+ if ( x%2 == 0 ){
+ h = (rows*x) + y;
+ }
+ else{
+ h = (rows*x) + (rows-y-1);
+ }
+
+ LEDChannels[h][0] = current_img[x][y][0];
+ LEDChannels[h][1] = current_img[x][y][1];
+ LEDChannels[h][2] = current_img[x][y][2];
+ }
+ }
+
+}
+
+void loop() {
+
+ //do something to modify the next_img
+ //this should be a big blinking 'H'
+ if ( current_frame%2 == 0 ){
+ memcpy_P( next_img , all_white , ( sizeof(next_img) ) );
+ }
+ else{
+ memcpy_P( next_img , hive_logo , ( sizeof(next_img) ) );
+ }
+
+ current_frame++;
+ if ( current_frame >= num_frames ) current_frame = 0;
+
+ //no need to alter below this point
+
+ //copy the next_img to the current_img
+ memcpy( current_img , next_img , sizeof(current_img) );
+ //memcpy( current_img , next_img , ( NumLEDs * 3 * sizeof(int) ) );
+
+ //change the 2D grid of values into a 1D chain of values
+ ConvertImg();
+
+ //write out the current array to the "display"
+ WriteLEDArray();
+
+ //pause between refresh
+ delay(400);
+
+}
View
BIN shiftbrite_random_led_V2/.DS_Store
Binary file not shown.
View
BIN shiftbrite_random_led_V2/applet/HardwareSerial.cpp.o
Binary file not shown.
View
BIN shiftbrite_random_led_V2/applet/Print.cpp.o
Binary file not shown.
View
BIN shiftbrite_random_led_V2/applet/WInterrupts.c.o
Binary file not shown.
View
BIN shiftbrite_random_led_V2/applet/WMath.cpp.o
Binary file not shown.
View
BIN shiftbrite_random_led_V2/applet/core.a
Binary file not shown.
View
BIN shiftbrite_random_led_V2/applet/pins_arduino.c.o
Binary file not shown.
View
147 shiftbrite_random_led_V2/applet/shiftbrite_random_led_V2.cpp
@@ -0,0 +1,147 @@
+// 2009 Kenneth Finnegan
+// kennethfinnegan.blogspot.com
+
+// Pins.
+#define clockpin 13 // CI
+#define enablepin 10 // EI
+#define latchpin 9 // LI
+#define datapin 11 // DI
+
+// Can't be higher than 255
+#define MAXBRIGHT 1023
+#define NumLEDs 48
+#define FADENUM 4
+
+// s[tate] t[arget] colors
+#include "WProgram.h"
+void setup();
+void SB_SendPacket();
+void WriteLEDArray();
+void loop();
+int s[NumLEDs][3] = {0}, t[NumLEDs][3] = {0};
+
+int LEDChannels[NumLEDs][3] = {0};
+int SB_CommandMode;
+int SB_RedCommand;
+int SB_GreenCommand;
+int SB_BlueCommand;
+
+void setup() {
+
+ // Make the random MORE RANDOM!
+ randomSeed(analogRead(0));
+
+ pinMode(datapin, OUTPUT);
+ pinMode(latchpin, OUTPUT);
+ pinMode(enablepin, OUTPUT);
+ pinMode(clockpin, OUTPUT);
+ SPCR = (1<<SPE)|(1<<MSTR)|(0<<SPR1)|(0<<SPR0);
+ digitalWrite(latchpin, LOW);
+ digitalWrite(enablepin, LOW);
+
+ SB_CommandMode = B01; // Write to current control registers
+ for (int z = 0; z < NumLEDs; z++) SB_SendPacket();
+ delayMicroseconds(15);
+ digitalWrite(latchpin,HIGH); // latch data into registers
+ delayMicroseconds(15);
+ digitalWrite(latchpin,LOW);
+}
+
+
+void SB_SendPacket() {
+
+ if (SB_CommandMode == B01) {
+ SB_RedCommand = 90;
+ SB_GreenCommand = 75;
+ SB_BlueCommand = 75;
+ }
+
+ SPDR = SB_CommandMode << 6 | SB_BlueCommand>>4;
+ while(!(SPSR & (1<<SPIF)));
+ SPDR = SB_BlueCommand<<4 | SB_RedCommand>>6;
+ while(!(SPSR & (1<<SPIF)));
+ SPDR = SB_RedCommand << 2 | SB_GreenCommand>>8;
+ while(!(SPSR & (1<<SPIF)));
+ SPDR = SB_GreenCommand;
+ while(!(SPSR & (1<<SPIF)));
+
+}
+
+void WriteLEDArray() {
+
+ SB_CommandMode = B00; // Write to PWM control registers
+ for (int h = 0;h<NumLEDs;h++) {
+ SB_RedCommand = LEDChannels[h][0];
+ SB_GreenCommand = LEDChannels[h][1];
+ SB_BlueCommand = LEDChannels[h][2];
+ SB_SendPacket();
+ }
+
+ delayMicroseconds(15);
+ digitalWrite(latchpin,HIGH); // latch data into registers
+ delayMicroseconds(15);
+ digitalWrite(latchpin,LOW);
+
+/*
+ SB_CommandMode = B01; // Write to current control registers
+ for (int z = 0; z < NumLEDs; z++) SB_SendPacket();
+ delayMicroseconds(15);
+ digitalWrite(latchpin,HIGH); // latch data into registers
+ delayMicroseconds(15);
+ digitalWrite(latchpin,LOW);
+ */
+}
+
+
+void loop() {
+ int i,j, offset;
+
+ for (j = 0; j < NumLEDs; j++) {
+
+ // check if this LED got to target - shift if not
+ if(s[j][0]!=t[j][0] || s[j][1]!=t[j][1] || s[j][2] != t[j][2]) {
+ for (i = 0; i<3; i++) {
+ if (s[j][i] > t[j][i]) {
+ s[j][i] = s[j][i] - 1;
+ } else if (s[j][i] < t[j][i]) {
+ s[j][i] = s[j][i] + 1;
+ }
+ }
+
+ } else {
+
+ // Select the next target color
+ // Start from a random one of the three colors to prevent
+ // the cycle from being red biased.
+ offset = random(3);
+ t[j][offset] = random(MAXBRIGHT);
+ t[j][(offset+1)%3] = random(MAXBRIGHT - t[j][offset]);
+ t[j][(offset+2)%3] = MAXBRIGHT - t[j][offset] - t[j][(offset+1)%3];
+ }
+
+ LEDChannels[j][0] = s[j][0];
+ LEDChannels[j][1] = s[j][1];
+ LEDChannels[j][2] = s[j][2];
+ }
+
+ WriteLEDArray();
+ //delay(1);
+
+
+ // Let the viewer enjoy the new color before
+ // selecting the next target color.
+ //delay(500);
+}
+
+int main(void)
+{
+ init();
+
+ setup();
+
+ for (;;)
+ loop();
+
+ return 0;
+}
+
View
1 shiftbrite_random_led_V2/applet/shiftbrite_random_led_V2.cpp.eep
@@ -0,0 +1 @@
+:00000001FF
View
BIN shiftbrite_random_led_V2/applet/shiftbrite_random_led_V2.cpp.elf
Binary file not shown.
View
154 shiftbrite_random_led_V2/applet/shiftbrite_random_led_V2.cpp.hex
@@ -0,0 +1,154 @@
+:100000000C9461000C947E000C947E000C947E0095
+:100010000C947E000C947E000C947E000C947E0068
+:100020000C947E000C947E000C947E000C947E0058
+:100030000C947E000C947E000C947E000C947E0048
+:100040000C94BB020C947E000C947E000C947E00F9
+:100050000C947E000C947E000C947E000C947E0028
+:100060000C947E000C947E00000000002400270009
+:100070002A0000000000250028002B0000000000DE
+:1000800023002600290004040404040404040202DA
+:100090000202020203030303030301020408102007
+:1000A0004080010204081020010204081020000012
+:1000B0000007000201000003040600000000000029
+:1000C000000011241FBECFEFD8E0DEBFCDBF11E08E
+:1000D000A0E0B1E0E8E7F9E002C005900D92A6309B
+:1000E000B107D9F714E0A6E0B1E001C01D92A7372F
+:1000F000B107E1F70E94B4020C94BA040C9400001A
+:10010000A0E0B0E0E6E8F0E00C948B04EC01A880FD
+:10011000B980CA80DB80A114B104C104D10441F4C8
+:1001200084E2A82E89EDB82E8BE5C82E87E0D82E64
+:10013000C601B5012DE133EF41E050E00E943204E9
+:1001400027EA31E440E050E00E9400047B018C018A
+:10015000C601B5012DE133EF41E050E00E943204C9
+:10016000CA01B9012CEE34EF4FEF5FEF0E9400049B
+:100170006E0D7F1D801F911F97FF04C0615070405E
+:1001800080409048688379838A839B839B01AC017C
+:100190005F77B901CA01CDB7DEB7EAE00C94A704D6
+:1001A0000E948000089580E091E00E948000089500
+:1001B0006093000170930101809302019093030109
+:1001C000089520916604309167042130310581F44F
+:1001D0008AE590E090936904809368048BE490E052
+:1001E00090936B0480936A0490936D0480936C04E5
+:1001F00040916C0450916D04CA01A4E095958795D7
+:10020000AA95E1F7F6E0220F331FFA95E1F7822B6A
+:100210008EBD0DB407FEFDCF2091680430916904B6
+:10022000C901E6E095958795EA95E1F774E0440FFA
+:10023000551F7A95E1F7842B8EBD0DB407FEFDCFD7
+:1002400040916A0450916B04852F992787FD9A95F8
+:10025000220F331F220F331F822B8EBD0DB407FEDA
+:10026000FDCF4EBD0DB407FEFDCF0895CF93DF93B4
+:100270001092670410926604C6E4D3E088819981E5
+:1002800090936904809368048A819B8190936B04A6
+:1002900080936A048C819D8190936D0480936C049B
+:1002A0000E94E100269684E0C636D80739F78FE031
+:1002B00090E00E94030389E061E00E9489038FE0DF
+:1002C00090E00E94030389E060E00E948903DF91CF
+:1002D000CF9108952F923F924F925F926F927F92AB
+:1002E0008F929F92AF92BF92CF92DF92EF92FF9246
+:1002F0000F931F93DF93CF9300D000D0CDB7DEB71D
+:1003000026E031E03C832B8346E252E05A83498366
+:1003100056E4252E53E0352E44245524EB81FC81F0
+:1003200020813181E981FA81808191812817390703
+:1003300059F4EB81FC8122813381E981FA81828148
+:1003400093812817390781F0C201880F991F840D06
+:10035000951D880F991FFC01EA5FFE4FDC01AA5D25
+:10036000BD4F40E050E00CC0EB81FC812481358121
+:10037000E981FA81848195812817390729F718C006
+:10038000808191812D913C9111972817390714F4A0
+:10039000019704C0821793071CF401969183808310
+:1003A0004F5F5F4F329612964330510549F754C064
+:1003B00063E070E080E090E00E94D6036B017C0176
+:1003C0006FEF73E080E090E00E94D6038201000F9F
+:1003D000111F040D151D38016C0C7D1C660C771C5B
+:1003E00026E232E0620E731EF301718360832FEF09
+:1003F00033E0261B370BB901882777FD8095982FAE
+:100400000E94D6034B015C01C601019663E070E0D7
+:100410000E941F04F801E80FF91FEE0FFF1FEA5DAD
+:10042000FD4F91828082C601029663E070E00E94D7
+:100430001F04080F191F000F111F0A5D1D4FF30144
+:10044000808191814FEF53E0481B590BCA018819F5
+:100450009909F80191838083EB81FC8180819181EE
+:10046000F10191838083EB81FC8182819381F10191
+:1004700093838283EB81FC8184819581F101958353
+:1004800084830894411C511C2B813C812A5F3F4F7F
+:100490003C832B8349815A814A5F5F4F5A8349834A
+:1004A00086E090E0280E391E90E34916510409F0C9
+:1004B00035CF0E9436010F900F900F900F90CF9183
+:1004C000DF911F910F91FF90EF90DF90CF90BF9041
+:1004D000AF909F908F907F906F905F904F903F90E4
+:1004E0002F900895CF93DF9380E00E944B030E94EA
+:1004F000F8038BE061E00E94690389E061E00E94FB
+:1005000069038AE061E00E9469038DE061E00E9476
+:10051000690380E58CBD89E060E00E9489038AE080
+:1005200060E00E94890381E090E0909367048093EB
+:100530006604C0E0D0E00E94E1002196C033D105FE
+:10054000D1F78FE090E00E94030389E061E00E9410
+:1005500089038FE090E00E94030389E060E00E943D
+:100560008903DF91CF9108950E9411030E947202C6
+:100570000E946A01FDCF1F920F920FB60F921124B5
+:100580002F933F938F939F93AF93BF938091720468
+:1005900090917304A0917404B09175043091760425
+:1005A0000196A11DB11D232F2D5F2D3720F02D5752
+:1005B0000196A11DB11D209376048093720490933F
+:1005C0007304A0937404B093750480916E049091A9
+:1005D0006F04A0917004B09171040196A11DB11D2A
+:1005E00080936E0490936F04A0937004B093710491
+:1005F000BF91AF919F918F913F912F910F900FBE1F
+:100600000F901F901895019759F0FC01EE0FFF1FF6
+:10061000EE0FFF1F32978FB7F8943197F1F78FBF26
+:100620000895789484B5826084BD84B5816084BD6A
+:1006300085B5826085BD85B5816085BDEEE6F0E05B
+:10064000808181608083E1E8F0E080818260808346
+:10065000808181608083E0E8F0E080818160808338
+:10066000E1EBF0E0808184608083E0EBF0E080816A
+:1006700081608083EAE7F0E080818460808380810C
+:1006800082608083808181608083808180688083B4
+:100690001092C10008958F70909104019295990F66
+:1006A000990F907C982B90937C0080917A008064C5
+:1006B00080937A0080917A0086FDFCCF20917800AB
+:1006C00040917900942F80E030E0282B392BC9012C
+:1006D0000895282F30E0C90186569F4FFC01949160
+:1006E0002A573F4FF9018491882391F0E82FF0E0D9
+:1006F000EE0FFF1FE859FF4FA591B491662329F42F
+:100700008C91909589238C9308958C91892B8C934F
+:100710000895482F50E0CA0182559F4FFC01249153
+:10072000CA0186569F4FFC0194914A575F4FFA01C8
+:1007300034913323D1F1222331F1233021F48091FC
+:1007400080008F7705C0243031F4809180008F7D48
+:100750008093800018C0213019F484B58F7704C0CD
+:10076000223021F484B58F7D84BD0DC0263021F464
+:100770008091B0008F7705C0273029F48091B000B8
+:100780008F7D8093B000E32FF0E0EE0FFF1FEE5857
+:10079000FF4FA591B491662329F48C9190958923FC
+:1007A0008C9308958C91892B8C930895EF92FF92EE
+:1007B0000F931F937B018C016115710581059105D4
+:1007C00029F420E030E040E050E00BC00E94D3006C
+:1007D000A80197010E943204AC01CB01DA019C010F
+:1007E000AD01B901CA011F910F91FF90EF900895DB
+:1007F000009729F0BC0180E090E00E94D8000895A5
+:10080000629FD001739FF001829FE00DF11D649FF4
+:10081000E00DF11D929FF00D839FF00D749FF00D80
+:10082000659FF00D9927729FB00DE11DF91F639F21
+:10083000B00DE11DF91FBD01CF011124089597FBF3
+:10084000092E07260AD077FD04D027D006D0002035
+:100850001AF4709561957F4F0895F6F790958195FC
+:100860009F4F089597FB092E05260ED057FD04D003
+:1008700028D00AD0001C38F4509540953095219529
+:100880003F4F4F4F5F4F0895F6F7909580957095C5
+:1008900061957F4F8F4F9F4F0895AA1BBB1B51E15E
+:1008A00007C0AA1FBB1FA617B70710F0A61BB70BE0
+:1008B000881F991F5A95A9F780959095BC01CD0185
+:1008C0000895A1E21A2EAA1BBB1BFD010DC0AA1F91
+:1008D000BB1FEE1FFF1FA217B307E407F50720F0A9
+:1008E000A21BB30BE40BF50B661F771F881F991F24
+:1008F0001A9469F760957095809590959B01AC016D
+:10090000BD01CF0108952F923F924F925F926F9257
+:100910007F928F929F92AF92BF92CF92DF92EF928F
+:10092000FF920F931F93CF93DF93CDB7DEB7CA1B10
+:10093000DB0B0FB6F894DEBF0FBECDBF09942A883B
+:10094000398848885F846E847D848C849B84AA84E3
+:10095000B984C884DF80EE80FD800C811B81AA8170
+:10096000B981CE0FD11D0FB6F894DEBF0FBECDBF3B
+:08097000ED010895F894FFCF9A
+:0609780001000000010077
+:00000001FF
View
BIN shiftbrite_random_led_V2/applet/shiftbrite_random_led_V2.cpp.o
Binary file not shown.
View
BIN shiftbrite_random_led_V2/applet/wiring.c.o
Binary file not shown.
View
BIN shiftbrite_random_led_V2/applet/wiring_analog.c.o
Binary file not shown.
View
BIN shiftbrite_random_led_V2/applet/wiring_digital.c.o
Binary file not shown.
View
BIN shiftbrite_random_led_V2/applet/wiring_pulse.c.o
Binary file not shown.
View
BIN shiftbrite_random_led_V2/applet/wiring_shift.c.o
Binary file not shown.
View
129 shiftbrite_random_led_V2/shiftbrite_random_led_V2.pde
@@ -0,0 +1,129 @@
+// 2009 Kenneth Finnegan
+// kennethfinnegan.blogspot.com
+
+// Pins.
+#define clockpin 13 // CI
+#define enablepin 10 // EI
+#define latchpin 9 // LI
+#define datapin 11 // DI
+
+// Can't be higher than 255
+#define MAXBRIGHT 1023
+#define NumLEDs 48
+#define FADENUM 4
+
+// s[tate] t[arget] colors
+int s[NumLEDs][3] = {0}, t[NumLEDs][3] = {0};
+
+int LEDChannels[NumLEDs][3] = {0};
+int SB_CommandMode;
+int SB_RedCommand;
+int SB_GreenCommand;
+int SB_BlueCommand;
+
+void setup() {
+
+ // Make the random MORE RANDOM!
+ randomSeed(analogRead(0));
+
+ pinMode(datapin, OUTPUT);
+ pinMode(latchpin, OUTPUT);
+ pinMode(enablepin, OUTPUT);
+ pinMode(clockpin, OUTPUT);
+ SPCR = (1<<SPE)|(1<<MSTR)|(0<<SPR1)|(0<<SPR0);
+ digitalWrite(latchpin, LOW);
+ digitalWrite(enablepin, LOW);
+
+ SB_CommandMode = B01; // Write to current control registers
+ for (int z = 0; z < NumLEDs; z++) SB_SendPacket();
+ delayMicroseconds(15);
+ digitalWrite(latchpin,HIGH); // latch data into registers
+ delayMicroseconds(15);
+ digitalWrite(latchpin,LOW);
+}
+
+
+void SB_SendPacket() {
+
+ if (SB_CommandMode == B01) {
+ SB_RedCommand = 90;
+ SB_GreenCommand = 75;
+ SB_BlueCommand = 75;
+ }
+
+ SPDR = SB_CommandMode << 6 | SB_BlueCommand>>4;
+ while(!(SPSR & (1<<SPIF)));
+ SPDR = SB_BlueCommand<<4 | SB_RedCommand>>6;
+ while(!(SPSR & (1<<SPIF)));
+ SPDR = SB_RedCommand << 2 | SB_GreenCommand>>8;
+ while(!(SPSR & (1<<SPIF)));
+ SPDR = SB_GreenCommand;
+ while(!(SPSR & (1<<SPIF)));
+
+}
+
+void WriteLEDArray() {
+
+ SB_CommandMode = B00; // Write to PWM control registers
+ for (int h = 0;h<NumLEDs;h++) {
+ SB_RedCommand = LEDChannels[h][0];
+ SB_GreenCommand = LEDChannels[h][1];
+ SB_BlueCommand = LEDChannels[h][2];
+ SB_SendPacket();
+ }
+
+ delayMicroseconds(15);
+ digitalWrite(latchpin,HIGH); // latch data into registers
+ delayMicroseconds(15);
+ digitalWrite(latchpin,LOW);
+
+/*
+ SB_CommandMode = B01; // Write to current control registers
+ for (int z = 0; z < NumLEDs; z++) SB_SendPacket();
+ delayMicroseconds(15);
+ digitalWrite(latchpin,HIGH); // latch data into registers
+ delayMicroseconds(15);
+ digitalWrite(latchpin,LOW);
+ */
+}
+
+
+void loop() {
+ int i,j, offset;
+
+ for (j = 0; j < NumLEDs; j++) {
+
+ // check if this LED got to target - shift if not
+ if(s[j][0]!=t[j][0] || s[j][1]!=t[j][1] || s[j][2] != t[j][2]) {
+ for (i = 0; i<3; i++) {
+ if (s[j][i] > t[j][i]) {
+ s[j][i] = s[j][i] - 1;
+ } else if (s[j][i] < t[j][i]) {
+ s[j][i] = s[j][i] + 1;
+ }
+ }
+
+ } else {
+
+ // Select the next target color
+ // Start from a random one of the three colors to prevent
+ // the cycle from being red biased.
+ offset = random(3);
+ t[j][offset] = random(MAXBRIGHT);
+ t[j][(offset+1)%3] = random(MAXBRIGHT - t[j][offset]);
+ t[j][(offset+2)%3] = MAXBRIGHT - t[j][offset] - t[j][(offset+1)%3];
+ }
+
+ LEDChannels[j][0] = s[j][0];
+ LEDChannels[j][1] = s[j][1];
+ LEDChannels[j][2] = s[j][2];
+ }
+
+ WriteLEDArray();
+ //delay(1);
+
+
+ // Let the viewer enjoy the new color before
+ // selecting the next target color.
+ //delay(500);
+}

0 comments on commit fc69471

Please sign in to comment.
Something went wrong with that request. Please try again.