#include <Adafruit_NeoPixel.h>
#define PIN_NEO_PIXEL 16 // The ESP32 pin GPIO16 connected to NeoPixel
#define NUM_PIXELS 30 // The number of LEDs (pixels) on NeoPixel LED strip
Adafruit_NeoPixel NeoPixel(NUM_PIXELS, PIN_NEO_PIXEL, NEO_GRB + NEO_KHZ800);
int tt=0;
int aa=4095/490;
void setup() {
NeoPixel.begin(); // initialize NeoPixel strip object (REQUIRED)
pinMode(12, INPUT);
Serial.begin(115200);
}
// 0~4095 = 4k 4096 ==> 10ms~500ms
void loop() {
NeoPixel.clear(); // set all pixel colors to 'off'. It only takes effect if pixels.show() is called
// turn pixels to green one-by-one with delay between each pixel
for (int pixel = 0; pixel < NUM_PIXELS; pixel++) { // for each pixel
NeoPixel.setPixelColor(pixel, NeoPixel.Color(0, 255, 0)); // it only takes effect if pixels.show() is called
NeoPixel.show(); // update to the NeoPixel Led Strip
int tt=analogRead(12);
tt=tt/aa;
if(tt>500)tt=500;
if(tt<10)tt=10;
Serial.println(tt);
delay(tt); // 200ms pause between each pixel
}
// turn off all pixels for two seconds
NeoPixel.clear();
NeoPixel.show(); // update to the NeoPixel Led Strip
delay(20); // 0.2 seconds off time
// turn on all pixels to red at the same time for two seconds
//for (int pixel = 0; pixel < NUM_PIXELS; pixel++) { // for each pixel
// NeoPixel.setPixelColor(pixel, NeoPixel.Color(255, 0, 0)); // it only takes effect if pixels.show() is called
//}
//NeoPixel.show(); // update to the NeoPixel Led Strip
//delay(10); // 0.1 second on time
// turn off all pixels for one seconds
//NeoPixel.clear();
//NeoPixel.show(); // update to the NeoPixel Led Strip
//delay(10); // 0.1 second off time
}