127 lines
2.5 KiB
C++
127 lines
2.5 KiB
C++
|
|
#include <Adafruit_NeoPixel.h>
|
|
|
|
#define PIN_ONOFF 6
|
|
#define PIN_FUNCTION1 7
|
|
#define PIN_FUNCTION2 8
|
|
#define PIN_LEDS 9
|
|
#define NUM_LEDS 124
|
|
#define NUM_LEDS_X 6
|
|
|
|
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN_LEDS, NEO_GRB + NEO_KHZ800);
|
|
|
|
bool boolOnOff;
|
|
bool toggleOnOff;
|
|
int intColour;
|
|
bool toggleColour;
|
|
|
|
void setup() {
|
|
pinMode(PIN_ONOFF, INPUT);
|
|
pinMode(PIN_FUNCTION1, INPUT);
|
|
Serial.begin(9600);
|
|
boolOnOff = 1;
|
|
toggleOnOff = 0;
|
|
intColour = 0;
|
|
toggleColour = 0;
|
|
strip.begin();
|
|
strip.show(); // Initialize all pixels to 'off'
|
|
Serial.println("My Sketch has started");
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
if (boolOnOff) {
|
|
Serial.println("ON");
|
|
|
|
if (toggleColour) {
|
|
if (intColour < 3) {
|
|
intColour++;
|
|
}
|
|
else {
|
|
intColour = 0;
|
|
}
|
|
}
|
|
|
|
switch (intColour) {
|
|
case 0: setAll(0xff,0xff,0xff);
|
|
toggleColour = 0;
|
|
break;
|
|
case 1: setAll(0xff,0x00,0x00);
|
|
toggleColour = 0;
|
|
break;
|
|
case 2: setAll(0x00,0xff,0x00);
|
|
toggleColour = 0;
|
|
break;
|
|
case 3: setAll(0x00,0x00,0xff);
|
|
toggleColour = 0;
|
|
break;
|
|
default:setAll(0x00,0x00,0x00);
|
|
toggleColour = 0;
|
|
}
|
|
|
|
while (digitalRead(PIN_FUNCTION1)){
|
|
toggleColour = 1;
|
|
delay(250);
|
|
}
|
|
|
|
}
|
|
else {
|
|
Serial.println("OFF");
|
|
setAll(0x00,0x00,0x00);
|
|
}
|
|
showStrip();
|
|
|
|
if (toggleOnOff){
|
|
boolOnOff = !boolOnOff;
|
|
toggleOnOff = 0;
|
|
}
|
|
else{
|
|
boolOnOff = boolOnOff;
|
|
}
|
|
|
|
while (digitalRead(PIN_ONOFF)){
|
|
toggleOnOff = 1;
|
|
delay(250);
|
|
}
|
|
|
|
|
|
Serial.println(intColour);
|
|
}
|
|
|
|
|
|
// Neopixel senden an Streifen
|
|
|
|
void showStrip() {
|
|
#ifdef ADAFRUIT_NEOPIXEL_H
|
|
// NeoPixel
|
|
strip.show();
|
|
#endif
|
|
}
|
|
|
|
|
|
// Neopixel setze einzelnen Pixel
|
|
|
|
void setPixel(int Pixel, byte red, byte green, byte blue) {
|
|
#ifdef ADAFRUIT_NEOPIXEL_H
|
|
// NeoPixel
|
|
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
|
|
#endif
|
|
}
|
|
|
|
|
|
// Neopixel setze ganzen Streifen
|
|
|
|
void setAll(byte red, byte green, byte blue) {
|
|
for(int i = NUM_LEDS_X; i < NUM_LEDS; i++ ) {
|
|
setPixel(i, red, green, blue);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|