remove temperature, add scheduler

This commit is contained in:
Marc Planard 2023-09-21 23:13:03 +02:00
parent 1ec552b85b
commit b3b7d0d818

View File

@ -1,39 +1,90 @@
#define LED 13 #define LED 13
#include "OneWire.h" // the granularity of scheduler is 2 minutes,
#include "DallasTemperature.h" // therefor we define the BI_MINUTE to be 2*60 seconds
#define BI_MINUTE (2*60*1000)
OneWire oneWire(A3); // our scheduler loop every 24 hour.
DallasTemperature ds(&oneWire); // 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() { void setup() {
// put your setup code here, to run once: // put your setup code here, to run once:
Serial.begin(115200); Serial.begin(115200);
delay(1000);
Serial.println("Starting.");
pinMode(LED, OUTPUT); 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() { void loop() {
// put your main code here, to run repeatedly: // put your main code here, to run repeatedly:
digitalWrite(LED, HIGH); digitalWrite(LED, HIGH);
for(int i=0; i < 100; ++i) { for(int i=0; i < 10; ++i) {
delay(50); delay(500);
print_light(); print_light();
} }
digitalWrite(LED, LOW); digitalWrite(LED, LOW);
for(int i=0; i < 100; ++i) { for(int i=0; i < 10; ++i) {
delay(50); delay(500);
print_light(); print_light();
} }
} }
*/
void print_light() { void print_light() {
int val = analogRead(A0); int val = analogRead(A0);
Serial.print("Light: "); Serial.print("Light: ");
Serial.print(val); Serial.println(val);
ds.requestTemperatures();
int t = ds.getTempCByIndex(0);
Serial.print("; Temp: ");
Serial.println(t);
} }