Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <Arduino.h>
#include <ESPectro32_Board.h>
#include <ESPectro32_RGBLED_Animation.h>
const int trigger = 2;
const int echo = 5;
int distance;
long duration;
RgbLedColor_t aCol(200, 0, 0);
RgbLedColor_t bCol(0, 200, 0);
ESPectro32_RGBLED_GlowingAnimation glowAnim1(ESPectro32.RgbLed(), aCol);
ESPectro32_RGBLED_GlowingAnimation glowAnim2(ESPectro32.RgbLed(), bCol);
void setup() {
ESPectro32.begin();
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);
}
void loop() {
digitalWrite(trigger,LOW);
delayMicroseconds(2);
digitalWrite(trigger,HIGH);
delayMicroseconds(10);
digitalWrite(trigger,LOW);
duration = pulseIn(echo,HIGH);
distance =duration/58.8;
if(distance>=0 || distance<=15){
glowAnim1.start();
}
if(distance>15){
glowAnim2.start();
}
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment