91 lines
1.6 KiB
C++
91 lines
1.6 KiB
C++
#define LED 13
|
|
|
|
// the granularity of scheduler is 2 minutes,
|
|
// therefor we define the BI_MINUTE to be 2*60 seconds
|
|
#define BI_MINUTE (2*60*1000)
|
|
|
|
// 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);
|
|
}
|
|
|
|
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 < 10; ++i) {
|
|
delay(500);
|
|
print_light();
|
|
}
|
|
digitalWrite(LED, LOW);
|
|
for(int i=0; i < 10; ++i) {
|
|
delay(500);
|
|
print_light();
|
|
}
|
|
}
|
|
*/
|
|
|
|
void print_light() {
|
|
int val = analogRead(A0);
|
|
Serial.print("Light: ");
|
|
Serial.println(val);
|
|
}
|