This commit is contained in:
lukario 2020-10-25 19:45:27 +01:00
parent 4700e004d0
commit 61174d05de

View File

@ -1,109 +0,0 @@
#include <Adafruit_NeoPixel.h>
#define PIN_ONOFF 2
#define PIN_FUNCTION1 3
#define PIN_FUNCTION2 4
#define PIN_LEDS 5
#define NUM_LEDS 124
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN_LEDS, NEO_GRB + NEO_KHZ800);
bool boolOnOff;
int intColour;
void setup() {
Serial.begin(9600);
boolOnOff = 1;
intColour = 0;
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Serial.println("My Sketch has started");
}
void loop() {
if (onOff(PIN_ONOFF,boolOnOff)) {
setColour(PIN_FUNCTION1,intColour);
Serial.println("ON");
}
else {
Serial.println("OFF");
setAll(0x00,0x00,0x00);
}
showStrip();
}
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
}
void setAll(byte red, byte green, byte blue) {
for(int i = 6; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
}
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;
}
}
bool onOff(int pinOnOff, bool varOnOff) {
if (pressedKey(pinOnOff)) {
Serial.print("Pressed");
Serial.println(pinOnOff);
varOnOff = !varOnOff;
}
return varOnOff;
}
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);
}
}