This commit is contained in:
lukario 2020-12-17 19:13:07 +01:00
parent 61174d05de
commit 4cb949566e

View File

@ -1,21 +1,28 @@
#include <Adafruit_NeoPixel.h> #include <Adafruit_NeoPixel.h>
#define PIN_ONOFF 2 #define PIN_ONOFF 6
#define PIN_FUNCTION1 3 #define PIN_FUNCTION1 7
#define PIN_FUNCTION2 4 #define PIN_FUNCTION2 8
#define PIN_LEDS 5 #define PIN_LEDS 9
#define NUM_LEDS 124 #define NUM_LEDS 124
#define NUM_LEDS_X 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN_LEDS, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN_LEDS, NEO_GRB + NEO_KHZ800);
bool boolOnOff; bool boolOnOff;
bool toggleOnOff;
int intColour; int intColour;
bool toggleColour;
void setup() { void setup() {
pinMode(PIN_ONOFF, INPUT);
pinMode(PIN_FUNCTION1, INPUT);
Serial.begin(9600); Serial.begin(9600);
boolOnOff = 1; boolOnOff = 1;
toggleOnOff = 0;
intColour = 0; intColour = 0;
toggleColour = 0;
strip.begin(); strip.begin();
strip.show(); // Initialize all pixels to 'off' strip.show(); // Initialize all pixels to 'off'
Serial.println("My Sketch has started"); Serial.println("My Sketch has started");
@ -25,15 +32,62 @@
void loop() { void loop() {
if (onOff(PIN_ONOFF,boolOnOff)) { if (boolOnOff) {
setColour(PIN_FUNCTION1,intColour);
Serial.println("ON"); 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 { else {
Serial.println("OFF"); Serial.println("OFF");
setAll(0x00,0x00,0x00); setAll(0x00,0x00,0x00);
} }
showStrip(); showStrip();
if (toggleOnOff){
boolOnOff = !boolOnOff;
toggleOnOff = 0;
}
else{
boolOnOff = boolOnOff;
}
while (digitalRead(PIN_ONOFF)){
toggleOnOff = 1;
delay(250);
}
Serial.println(intColour);
} }
@ -60,67 +114,13 @@
// Neopixel setze ganzen Streifen // Neopixel setze ganzen Streifen
void setAll(byte red, byte green, byte blue) { void setAll(byte red, byte green, byte blue) {
for(int i = 6; i < NUM_LEDS; i++ ) { for(int i = NUM_LEDS_X; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue); setPixel(i, red, green, blue);
} }
} }
// Entstörung des Schaltsignal des Tasters durch Delay | Anmerkung an mich ggf. nur die abfallende Flanke abfragen? und/oder mit Flankenmerker statt Schleife arbeiten
bool pressedKey (int keyIn) {
if (digitalRead(keyIn) == 1) {
delay(500);
if (digitalRead(keyIn) == 1) {
while (digitalRead(keyIn) == 1) {
delay(500);
}
return 1;
}
else {
return 0;
}
}
else {
return 0;
}
}
// Schaltet den LED-Streifen Ein und/oder Aus
bool onOff(int pinOnOff, bool varOnOff) {
if (pressedKey(pinOnOff)) {
Serial.print("Pressed");
Serial.println(pinOnOff);
varOnOff = !varOnOff;
}
return varOnOff;
}
//Setzt die Farbe des LED-Streifens
void setColour(int pinSetColour, int varColour) {
if (pressedKey(pinSetColour)) {
if (varColour < 3) {
varColour++;
}
else {
varColour = 0;
}
}
switch (varColour) {
case 0: setAll(0xff,0xff,0xff);
break;
case 1: setAll(0xff,0x00,0x00);
break;
case 2: setAll(0x00,0xff,0x00);
break;
case 3: setAll(0x00,0x00,0xff);
break;
default:setAll(0x00,0x00,0x00);
}
}