#define LED_PIN 2 // ESP32 pin GPIO18 connected to LED
unsigned long previousMillis = 0;
unsigned ledLong = 0;
unsigned dhtLong = 0;
int lightCount = 0;
void setup() {
pinMode(LED_PIN,OUTPUT);
digitalWrite(LED_PIN, LOW); //off
Serial.begin(115200);
Serial.println("Setup");
}
void sosLed(unsigned long currentMillis) {
// 0 1 2 3 4 5 6 7 8 9 10 11
byte counts[] = {1, 1,1, 1,1, 1,1,2,1,2, 1, 2,};
if(lightCount > 11) {
lightCount = 0;
}
// Serial.println(lightCount);
if(ledLong >= counts[lightCount]) {
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
ledLong = 0;
lightCount = lightCount + 1;
} else {
ledLong = ledLong + currentMillis - previousMillis;
}
}
void readDht(unsigned long currentMillis) {
if(dhtLong >= 19) {
dhtLong = 0;
Serial.print(currentMillis);
Serial.print(" DHT call");
Serial.println("");
} else {
dhtLong = dhtLong + currentMillis - previousMillis;
Serial.println(dhtLong);
}
}
void loop() {
unsigned long currentMillis = (millis()/100);
if (currentMillis - previousMillis >= 1) {
//
sosLed(currentMillis);
// readDht(currentMillis);
//
previousMillis = currentMillis;
}
}