ESP32-Bac-Semis/esp32_blink.ino

91 lines
1.6 KiB
Arduino
Raw Permalink Normal View History

2023-01-05 21:05:51 +00:00
#define LED 13
2023-09-21 21:13:03 +00:00
// the granularity of scheduler is 2 minutes,
// therefor we define the BI_MINUTE to be 2*60 seconds
#define BI_MINUTE (2*60*1000)
2023-01-05 21:05:51 +00:00
2023-09-21 21:13:03 +00:00
// 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;
2023-01-05 21:05:51 +00:00
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
2023-09-21 21:13:03 +00:00
delay(1000);
Serial.println("Starting.");
2023-01-05 21:05:51 +00:00
pinMode(LED, OUTPUT);
}
2023-09-21 21:13:03 +00:00
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);
}
/*
2023-01-05 21:05:51 +00:00
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED, HIGH);
2023-09-21 21:13:03 +00:00
for(int i=0; i < 10; ++i) {
delay(500);
2023-01-05 21:05:51 +00:00
print_light();
}
digitalWrite(LED, LOW);
2023-09-21 21:13:03 +00:00
for(int i=0; i < 10; ++i) {
delay(500);
2023-01-05 21:05:51 +00:00
print_light();
}
}
2023-09-21 21:13:03 +00:00
*/
2023-01-05 21:05:51 +00:00
void print_light() {
int val = analogRead(A0);
Serial.print("Light: ");
2023-09-21 21:13:03 +00:00
Serial.println(val);
2023-01-05 21:05:51 +00:00
}