7192| 2
|
[求助] 想用按键中断产生一个随机数点亮WS2812灯环 |
请教大家一个Arduino问题,想用按键中断产生一个随机数点亮WS2812灯环,但每次都同时点亮多个是哪里问题。 #include <Adafruit_NeoPixel.h> #define PIN 6 #define NUMPIXELS 16 Adafruit_NeoPixel strip = Adafruit_NeoPixel (NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800); int delayval = 1000; volatile int state = LOW; void setup() { // put your setup code here, to run once: strip.begin(); strip.show(); attachInterrupt(1, stateChange, CHANGE); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: for(int i=0; i<16; i++) { for(int a=0; a<16; a++) { if(a == i) strip.setPixelColor(a, 5, 15, 0); else strip.setPixelColor(a,0); strip.show(); } delay(1000); } } void stateChange() { int r = random(15); strip.setPixelColor(r, 5, 25, 0); strip.show(); Serial.println(r); delay(5000); } |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed