Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This #include statement was automatically added by the Spark IDE.
- #include "SparkIntervalTimer/SparkIntervalTimer.h"
- #include "LPD6803.h"
- int dataPin = D3; // 'yellow' wire (Arduino 4) [WAS D3]
- int clockPin = D4; // 'white' wire (Arduino 7) [WAS D4]
- // Don't forget to connect 'blue' to ground and 'red' to +5V
- // Set the first variable to the NUMBER of pixels. 20 = 20 pixels in a row
- LPD6803 strip = LPD6803(50, dataPin, clockPin);
- int numberofracks=8;
- int setflag=0;
- int initflag=0;
- // Set first element to the number of racks
- uint8_t rackdata[8][3]= {
- {0,0,0}, //
- {0,0,0}, //
- {0,0,0}, //
- {0,0,0}, //
- {0,0,0}, //
- {0,0,0}, //
- {0,0,0}, //
- {0,0,0}, //
- };
- void setup() {
- Spark.function("ledSet", ledSet); // expects 'd' separated integers (racknum,red,green,blue)
- // curl https://api.spark.io/v1/devices/jjcore1/ledset -d access_token=$TOKENID -d "c=4-32-32-32-"
- // API Works with next line commented out (but lights don't function)
- // initflag=1;
- }
- void loop() {
- if (initflag ==1) {
- strip.begin();
- strip.show();
- delay(50);
- colorWipe(Color(0,0,0),50);
- delay(50);
- initflag=0;
- }
- if (setflag == 1) {
- setall();
- setflag=0;
- delay(50);
- }
- /*
- int r, f;
- for (r=1; r<9; r++) {
- for (f=0; f<6; f++) {
- rackWipe(Color(0, 0, 63), 50, r); // Make rack r red
- delay(50);
- rackWipe(Color(15, 0, 0), 50, r); // Make rack r blue
- delay(50);
- }
- }
- */
- }
- void setall() {
- uint8_t rc;
- for (rc=0; rc<numberofracks; rc++) {
- rackWipe(Color(rackdata[rc][2], rackdata[rc][1], rackdata[rc][0]), 50, rc+1);
- delay (50);
- }
- }
- // fill the dots one after the other with said color
- // good for testing purposes
- void colorWipe(uint16_t c, uint8_t wait) {
- int i;
- for (i=0; i < strip.numPixels(); i++) {
- strip.setPixelColor(i, c);
- strip.show();
- delay(wait);
- }
- }
- // fill the dots one after the other with said color
- // good for testing purposes
- void rackWipe(uint16_t c, uint8_t wait, uint8_t rack) {
- int i;
- for (i=(rack*6)-6; i < (rack*6); i++) {
- strip.setPixelColor(i, c);
- strip.show();
- delay(wait);
- }
- }
- int ledSet(String c) {
- int racknum;
- int red;
- int green;
- int blue;
- int loc1=0;
- int loc2=0;
- int loc3=0;
- int loc4=0;
- if (setflag==1) {
- return -1;
- }
- loc1 = c.indexOf("-");
- racknum = c.substring(0,loc1).toInt();
- loc2 = c.indexOf("-",loc1+1);
- red = c.substring(loc1+1,loc2).toInt();
- loc3 = c.indexOf("-",loc2+1);
- green = c.substring(loc2+1,loc3).toInt();
- loc4 = c.indexOf("-",loc3+1);
- blue = c.substring(loc3+1,loc4).toInt();
- rackdata[racknum-1][0]=red;
- rackdata[racknum-1][1]=green;
- rackdata[racknum-1][2]=blue;
- setflag=1;
- return (racknum-1);
- }
- /* Helper functions */
- // Create a 15 bit color value from R,G,B
- unsigned int Color(byte r, byte g, byte b)
- {
- //Take the lowest 5 bits of each value and append them end to end
- return( ((unsigned int)g & 0x1F )<<10 | ((unsigned int)b & 0x1F)<<5 | (unsigned int)r & 0x1F);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement