56 lines
1.6 KiB
Arduino
56 lines
1.6 KiB
Arduino
|
#include <FastLED.h>
|
||
|
|
||
|
// How many leds in your strip?
|
||
|
#define NUM_LEDS 38
|
||
|
|
||
|
// For led chips like WS2812, which have a data line, ground, and power, you just
|
||
|
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
|
||
|
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
|
||
|
// Clock pin only needed for SPI based chipsets when not using hardware SPI
|
||
|
#define DATA_PIN 26
|
||
|
|
||
|
// Define the array of leds
|
||
|
CRGB leds[NUM_LEDS];
|
||
|
unsigned long data_in = 0;
|
||
|
unsigned long data_off= 50;
|
||
|
int NUM = 10;
|
||
|
unsigned long time_on = millis();
|
||
|
unsigned long time_off = millis();
|
||
|
|
||
|
void setup() {
|
||
|
Serial.begin(115200);
|
||
|
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // GRB ordering is assumed
|
||
|
delay(1000); // give me time to bring up serial monitor
|
||
|
Serial.println("ESP32 Touch Test");
|
||
|
for(int i=0; i<NUM; i++) data_in+=touchRead(4);
|
||
|
data_in = data_in/NUM;
|
||
|
data_off = data_in;
|
||
|
data_in = 0;
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
for(int i=0; i<NUM; i++) data_in+=touchRead(4);
|
||
|
data_in = data_in/NUM;
|
||
|
if (data_in<data_off-1)
|
||
|
{
|
||
|
time_off = millis();
|
||
|
if((millis()-time_on)>=100)
|
||
|
{
|
||
|
for(int i=0; i<NUM_LEDS; i++) leds[i] = CRGB::White;
|
||
|
time_on = millis();
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
time_on = millis();
|
||
|
if((millis()-time_off)>=100)
|
||
|
{
|
||
|
for(int i=0; i<NUM_LEDS; i++) leds[i] = CRGB::Black;
|
||
|
time_off = millis();
|
||
|
}
|
||
|
}
|
||
|
FastLED.show();
|
||
|
Serial.println(data_in); // get value of Touch 0 pin = GPIO 4
|
||
|
data_in = 0;
|
||
|
}
|