1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
#include <Adafruit_NeoPixel.h> Adafruit_NeoPixel stripH=Adafruit_NeoPixel(2, 3, NEO_GRB + NEO_KHZ800); unsigned long cnt1=0; unsigned long cnt2=0; int states=0; void setup() { stripH.begin(); stripH.show(); pinMode(11, INPUT); } void loop() { if (digitalRead(11)==HIGH && cnt1==0) { cnt1=millis(); } else if (digitalRead(11)==HIGH && millis() > cnt1+2000) { states=1; } else if (digitalRead(11)==LOW) { cnt1=0; } if (states==1) { if (cnt2==0) { cnt2=millis(); stripH.setPixelColor(1, stripH.Color(0, 0, 0)); stripH.setPixelColor(0, stripH.Color(0, 255, 0)); } else if (millis() > cnt2+5000) { cnt2=0; states=0; } } else { stripH.setPixelColor(1, stripH.Color(255, 0, 0)); stripH.setPixelColor(0, stripH.Color(0, 0, 0)); } stripH.show(); } |