#include <FastLED.h>
#define NUM_LEDS 10
#define DATA_PIN 16 //How boring and obvious!
#define COLOR_ORDER GRB //Green (G), Red (R), Blue (B)
#define CHIPSET WS2812B
#define BRIGHTNESS 255
#define VOLTS 5
#define MAX_AMPS 20000 //value in milliamps
const byte interruptPin = 17;
volatile byte state = LOW;
int tCount = 0;
CRGB leds[NUM_LEDS];
String butStr;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
butStr = String("Buttons: ");
FastLED.addLeds<CHIPSET, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS, MAX_AMPS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
FastLED.show();
}
void loop() {
// put your main code here, to run repeatedly:
bool RedButOn = (digitalRead(17));
bool GrnButOn = (digitalRead(5));
bool BluButOn = (digitalRead(18));
butStr.concat(digitalRead(17));
butStr.concat(digitalRead(5));
butStr.concat(digitalRead(18));
Serial.println(butStr);
butStr = String("Buttons: ");
if (RedButOn) {
//FastLED.showColor(CRGB::Red);
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB(0, 255 - 10 * i, 10 * i);
FastLED.show();
millisDelay(30);
}
for (int i = NUM_LEDS - 1; i >= 0; i--) {
leds[i] = CRGB(10 * i, 0, 255 - 10 * i);
FastLED.show();
millisDelay(30); //even shorter delay this time
}
RedButOn = false;
} else if (GrnButOn) {
FastLED.showColor(CRGB::Green);
GrnButOn = false;
} else if (BluButOn) {
FastLED.showColor(CRGB::Blue);
BluButOn = false;
} else {
FastLED.showColor(CRGB::Black);
}
//leds[0] = CRGB::White; FastLED.show(); delay(30);
//leds[0] = CRGB::Black; FastLED.show(); delay(30);
delay(10); // this speeds up the simulation
Serial.println(tCount++);
}
void millisDelay( long int delayTime) {
long int start_time = millis();
while ( millis() - start_time < delayTime) ;
}