diff --git a/esp32_blink.ino b/esp32_blink.ino index f2ee64d..c1ebc3a 100644 --- a/esp32_blink.ino +++ b/esp32_blink.ino @@ -1,39 +1,90 @@ #define LED 13 -#include "OneWire.h" -#include "DallasTemperature.h" +// the granularity of scheduler is 2 minutes, +// therefor we define the BI_MINUTE to be 2*60 seconds +#define BI_MINUTE (2*60*1000) -OneWire oneWire(A3); -DallasTemperature ds(&oneWire); +// our scheduler loop every 24 hour. +// one hour is represented by 1 unsigned int +// each bit of the hour represent one BI_MINUTE. +// the output of the scheduler is ON if one bit is set, OFF otherwise. +unsigned int scheduler[24] = { + 0b00000000000000000111111111111111, // here we set the output ON from 0 to 15th biminute so half of the hour + 0, // all other hours are set to 0 + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +}; + +// variables to keep track of the current our and biminute. +int hour=0; +int biminute=0; void setup() { // put your setup code here, to run once: Serial.begin(115200); + delay(1000); + Serial.println("Starting."); pinMode(LED, OUTPUT); - ds.begin(); } +void loop() { + if ((scheduler[hour] >> biminute) & 1) { + digitalWrite(LED, HIGH); + Serial.println("Scheduler: ON"); + } else { + digitalWrite(LED, LOW); + Serial.println("Scheduler: OFF"); + } + + biminute += 1; + if(biminute >= 30) { + biminute = 0; + hour += 1; + if(hour >= 24) { + hour = 0; + } + } + delay(BI_MINUTE); +} + +/* void loop() { // put your main code here, to run repeatedly: digitalWrite(LED, HIGH); - for(int i=0; i < 100; ++i) { - delay(50); + for(int i=0; i < 10; ++i) { + delay(500); print_light(); } digitalWrite(LED, LOW); - for(int i=0; i < 100; ++i) { - delay(50); + for(int i=0; i < 10; ++i) { + delay(500); print_light(); } } +*/ void print_light() { int val = analogRead(A0); Serial.print("Light: "); - Serial.print(val); - - ds.requestTemperatures(); - int t = ds.getTempCByIndex(0); - Serial.print("; Temp: "); - Serial.println(t); + Serial.println(val); }