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 53 54 55 56 57 58 59 |
#include <Adafruit_NeoPixel.h> #define LED_PIN 3 #define LED_COUNT 8 Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); unsigned long cnt=0; int number=8; // 네오픽셀의 번호 int number2=0; // 밝기 int s=0; void setup() { Serial.begin(9600); strip.begin(); strip.show(); strip.setBrightness(255); // 0~255 } void loop() { if (millis() > cnt+1000) { cnt=millis(); s++; if (s>=60) { s=0; } } number=int(s/60.0*8); number2=map(int(s/60.0*8*10)%10, 0, 10, 0, 255); Serial.print("s : "); Serial.print(s); Serial.print(", n : "); Serial.print(number); Serial.print(", b : "); Serial.print(number2); Serial.println(); for (int i=0;i<strip.numPixels();i++) { if (i > number) { strip.setPixelColor(i, strip.Color(0, 0, 0)); } else if (i==number) { strip.setPixelColor(i, strip.Color(number2, number2, number2)); } else { strip.setPixelColor(i, strip.Color(255, 255, 255)); } strip.show(); } } |