Tu je projekt ale zatial funguje s jedným tlačítkom..
Kód: Vybrat vše
#include <Adafruit_NeoPixel.h>
#define BUTTON_PIN 2
#define PIXEL_PIN 9
#define PIXEL_COUNT 34
int brightness = 255;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
bool oldState = HIGH;
int showType = 0;
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin();
strip.setBrightness(brightness);
strip.show();
}
void loop() {
bool newState = digitalRead(BUTTON_PIN);
if (newState == LOW && oldState == HIGH) {
delay(20);
newState = digitalRead(BUTTON_PIN);
if (newState == LOW) {
showType++;
if (showType > 2)
showType=0;
startShow(showType);
}
}
oldState = newState;
}
void startShow(int i) {
switch(i){
case 0: colorWipe(strip.Color(0, 0, 0), 40);
break;
case 1: colorWipe(strip.Color(225, 255, 255), 40);
break;
case 2: colorWipe(strip.Color(255, 0, 0), 40);
break;
}
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<(strip.numPixels()/2); i++) {
strip.setPixelColor((strip.numPixels()/2-1)-i, c);
strip.setPixelColor((((strip.numPixels()/2)+i)), c);
strip.show();
delay(wait);
}
}