#include #include /***************************************************************************** Example sketch for driving Adafruit WS2801 pixels! Designed specifically to work with the Adafruit RGB Pixels! 12mm Bullet shape ----> https://www.adafruit.com/products/322 12mm Flat shape ----> https://www.adafruit.com/products/738 36mm Square shape ----> https://www.adafruit.com/products/683 These pixels use SPI to transmit the color data, and have built in high speed PWM drivers for 24 bit color per pixel 2 pins are required to interface Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, all text above must be included in any redistribution *****************************************************************************/ int dataPin = 3; // Yellow wire int clockPin = 2; // Green wire int PIXEL = 80; #define StartTag "s" int ProgrammNummer = 0; int gruen; int rot; int blau; int Funktion; int StopTag = 0; int Programmwechsel = 1; Adafruit_WS2801 strip = Adafruit_WS2801(PIXEL, dataPin, clockPin); //////////////////////////////////////////////////////////////////////////////////////////////////////////// void setup() { pinMode(dataPin,OUTPUT); pinMode(clockPin,OUTPUT); digitalWrite(13,LOW); Serial.begin(9600); strip.begin(); strip.show(); } //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// void loop() { ProgrammNummer = 0; StopTag = 0; if(Programmwechsel != 0) { clearPIXEL(); strip.show(); Programmwechsel = 0; } if(Serial.available()) { if(Serial.find(StartTag)) { while(Serial.available() < 1); ProgrammNummer = Serial.parseInt(); } } switch(ProgrammNummer) // Programmauswahl { case 1: // Programm 1 digitalWrite(13,HIGH); Programm_one(); Programmwechsel = 1; FLUSH(); break; case 2: // Programm 2 digitalWrite(13,HIGH); Programm_two(); Programmwechsel = 1; FLUSH(); break; case 3: // Programm 3 digitalWrite(13,HIGH); Programm_three(); Programmwechsel = 1; FLUSH(); break; case 4: // Programm 4 digitalWrite(13,HIGH); Programm_four(); Programmwechsel = 1; FLUSH(); break; case 5: // Programm 5 digitalWrite(13,HIGH); Programm_five(); Programmwechsel = 1; FLUSH(); break; case 6: // Programm 6 digitalWrite(13,HIGH); Programm_six(); Programmwechsel = 1; FLUSH(); break; default: break; } } //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// void Programm_one() { int jj,xx; int Array_eins[17][6] ={ {5,6,7,72,73,74}, {4,8,71,75,99,99}, {3,9,70,76,99,99}, {2,10,69,77,99,99}, {0,1,78,79,99,99}, {11,34,68,45,99,99}, {11,33,35,68,46,44}, {12,32,36,43,47,67}, {13,31,37,42,48,66}, {14,30,38,41,49,65}, {15,29,39,40,50,64}, {16,28,51,63,99,99}, {17,27,52,62,99,99}, {18,26,53,61,99,99}, {19,25,54,60,99,99}, {20,24,55,59,99,99}, {21,22,23,56,57,58} }; FLUSH(); while(1) { SerialAbfrage(); if(StopTag != 0) break; uint32_t c = Color(gruen,rot,blau); for(jj=0; jj < 17; jj++) { for(xx=0; xx < 6; xx++) { strip.setPixelColor(Array_eins[jj][xx], c); strip.show(); } } clearPIXEL(); //als Funktion füllen von oben nach unten if(Funktion == 1) { for(jj=16; jj > 0 ; jj--) { for(xx=0; xx < 6; xx++) { strip.setPixelColor(Array_eins[jj][xx], c); strip.show(); } } clearPIXEL(); } } } //////////////////////////////////////////////////////////////////////////////////////////////////////////// void Programm_two() { while(1) { SerialAbfrage(); if(StopTag != 0) break; int a = random(strip.numPixels()); int b = random(1200000); int bb = random(1200); int bbb = random(1200000); int bbbb = random(120000); int x = random(25); strip.setPixelColor(a,b); strip.setPixelColor(a+3,bb); strip.setPixelColor(a+6+x,bbb); strip.setPixelColor(a+9+x,bbbb); strip.setPixelColor(a+12+x,bb); strip.setPixelColor(a+15+x,bbbb); strip.setPixelColor(a+25+x,bbbb); strip.setPixelColor(a+19+x,bb); strip.setPixelColor(a+30+x,bbbb); strip.show(); delay(80); for(int i=0;i= 0; j--) { for(int x=0; x < 6; x++) { strip.setPixelColor(Array_eins[j][x], c); strip.show(); strip.setPixelColor(Array_eins[j-1][x], c); strip.setPixelColor(Array_eins[j][x], 0); } } } } } //////////////////////////////////////////////////////////////////////////////////////////////////////////// void Programm_six() { while(1) { SerialAbfrage(); if(StopTag != 0) break; rainbow(20); rainbowCycle(20); } } void rainbow(uint8_t wait) { int i, j; for (j=0; j < 256; j++) { // 3 cycles of all 256 colors in the wheel for (i=0; i < strip.numPixels(); i++) { strip.setPixelColor(i, Wheel( (i + j) % 255)); } strip.show(); // write all the pixels out delay(wait); } } void rainbowCycle(uint8_t wait) { int i, j; for (j=0; j < 256 * 5; j++) { // 5 cycles of all 25 colors in the wheel for (i=0; i < strip.numPixels(); i++) { // tricky math! we use each pixel as a fraction of the full 96-color wheel // (thats the i / strip.numPixels() part) // Then add in j which makes the colors go around per pixel // the % 96 is to make the wheel cycle around strip.setPixelColor(i, Wheel( ((i * 256 / strip.numPixels()) + j) % 256) ); } strip.show(); // write all the pixels out delay(wait); } } uint32_t Wheel(byte WheelPos) { if (WheelPos < 85) { return Color(WheelPos * 3, 255 - WheelPos * 3, 0); } else if (WheelPos < 170) { WheelPos -= 85; return Color(255 - WheelPos * 3, 0, WheelPos * 3); } else { WheelPos -= 170; return Color(0, WheelPos * 3, 255 - WheelPos * 3); } } //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// void FLUSH() { while(Serial.available()>0) { Serial.read(); } } //////////////////////////////////////////////////////////////////////////////////////////////////////////// void SerialAbfrage() { if(Serial.available()) { if(Serial.find(StartTag)) { while(Serial.available() < 1); StopTag = Serial.parseInt(); gruen = Serial.parseInt(); rot = Serial.parseInt(); blau = Serial.parseInt(); Funktion = Serial.parseInt(); } while(Serial.available()>0) { Serial.read(); } } } //////////////////////////////////////////////////////////////////////////////////////////////////////////// void clearPIXEL() { int i; for(i=0 ; i<=strip.numPixels(); i++) { strip.setPixelColor(i,0); } } //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// // Create a 24 bit color value from G,R,B uint32_t Color(byte g, byte r, byte b) { uint32_t c; c = g; c <<= 8; c |= r; c <<= 8; c |= b; //Serial.println(c); return c; } //////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////