/* The TLC5940 library must be installed first: Copy (or symlink) the TLC5940 folder to /hardware/libraries/ */ #include // Parameter 1 is number of tlc5940 chips in series, // parameter 2 is number of grayscale bits per led. TLC5940 leds(3, 8); int RED[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int BLUE[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int GREEN[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int x, y, z; byte ledcounter = 0; int intcounter = 0; int updown = 0; int Rcount, Gcount, Bcount; int xcount, ycount, zcount; static void setEye(uint8_t eyeid, uint32_t rgb) { leds.setLED(eyeid*3, (rgb >> 16) & 0xff); leds.setLED(eyeid*3+1, (rgb >> 8) & 0xff); leds.setLED(eyeid*3+2, rgb & 0xff); } static void setEye(uint8_t eyeid, uint8_t r, uint8_t g, uint8_t b) { leds.setLED(eyeid*3, r); leds.setLED(eyeid*3+1, g); leds.setLED(eyeid*3+2, b); } void setup() { Serial.begin(115200); // FIXME: Pin allocation should be configures here leds.init(); leds.clear(); // Clear framebuffer leds.display(); // Display framebuffer Serial.println("TLC5940 tester"); } // Some super-simple test animation void loop() { colorwave(); myclear(); } void shiftleft() { for(int x = 15; x > 0; --x) { BLUE[x] = BLUE[x-1]; RED[x] = RED[x-1]; GREEN[x] = GREEN[x-1]; } BLUE[0] = 0; RED[0] = 0; GREEN[0] = 0; } void mydisplay() { for(int x = 0; x < 16; x++) { leds.setLED(x*3, BLUE[x]); leds.setLED((x*3)+1, GREEN[x]); leds.setLED((x*3)+2, RED[x]); } leds.display(); } void colorwave() { for(int w = 0; w < 16; w ++) { if(w < 8) { GREEN[0] = w * (255 / 8); } if(w >= 8) { GREEN[0] = (255 - (255 / 8) * (w%8) ); } RED[0] = 0; BLUE[0] = 0; mydisplay(); shiftleft(); delay(100); } for(int w = 0; w < 16; w ++) { if(w < 8) { BLUE[0] = w * (255 / 8); } if(w >= 8) { BLUE[0] = (255 - (255 / 8) * (w%8) ); } GREEN[0] = 0; RED[0] = 0; mydisplay(); shiftleft(); delay(100); } for(int w = 0; w < 16; w ++) { if(w < 8) { RED[0] = w * (255 / 8); } if(w >= 8) { RED[0] = (255 - (255 / 8) * (w%8) ); } GREEN[0] = 0; BLUE[0] = 0; mydisplay(); shiftleft(); delay(100); } } void myclear() { for(int x = 0 ; x < 17 ; x++) { RED[0] = 0; BLUE[0] = 0; GREEN[0] = 0; shiftleft(); mydisplay(); delay(100); } } void waves() { if(x < 8) { GREEN[0] = x * (255 / 8); xcount = 0; } if(x >= 8) { GREEN[0] = (255 - (255 / 8) * (x%8) ); } if(x == 15 && xcount < 10) { xcount++; GREEN[0] = 0; } else{ x++; x = x%16; } if(y < 8) { BLUE[0] = y * (255 / 8); ycount = 0; } if(y >= 8) { BLUE[0] = (255 - (255 / 8) * (y%8) ); } if(y == 15 && ycount < 9) { ycount++; BLUE[0] = 0; } else{ y++; y = y%16; } if(z < 8) { RED[0] = z * (255 / 8); zcount = 0; } if(z >= 8) { RED[0] = (255 - (255 / 8) * (z%8) ); } if(z == 15 && zcount < 11) { zcount++; RED[0] = 0; } else{ z++; z = z%16; } mydisplay(); shiftleft(); delay(100); } void banner() { for(Rcount = 0 ; Rcount < 16 ; Rcount++) //once per LED { for(int x = 0 ; x <= Rcount ; x++) { leds.setLED(x*3, ((x+1) * (255/16))); } leds.display(); delay(100); } } void chase() { for (int i = 0; i<16; i++) { leds.clear(); setEye(i, 255, 255, 255); leds.display(); delay(50); } leds.clear(); leds.display(); delay(300); for (int i = 15; i!=-1; i--) { leds.clear(); setEye(i, 0, 255, 255); leds.display(); delay(50); } leds.clear(); leds.display(); delay(300); for (int i = 0; i<16; i++) { leds.clear(); setEye(i, 255, 0, 255); leds.display(); delay(50); } leds.clear(); leds.display(); delay(300); for (int i = 15; i!=-1; i--) { leds.clear(); setEye(i, 255, 255, 0); leds.display(); delay(50); } leds.clear(); leds.display(); delay(300); }