Files
Alarm_Clock/Wecker/radio.ino
Christian Mittring 9d75a64173 First Commit
2018-04-01 12:29:12 +02:00

109 lines
1.9 KiB
C++

void round_sleep(){
if (minutes_sleep > 60){
minutes_sleep = 60;
}
else if (minutes_sleep > 45){
minutes_sleep = 45;
}
else if (minutes_sleep > 30){
minutes_sleep = 30;
}
else if (minutes_sleep > 15){
minutes_sleep = 15;
}
else if (minutes_sleep > 0){
minutes_sleep = 0;
}
else{
minutes_sleep = 90;
}
setSleepTimer(minutes_sleep);
}
void setSleepTimer(long Minutes){
if (Minutes == 0)
{
time_on = -1;
minutes_sleep = -1;
}
else{
unsigned long currentMillis = millis();
time_on = currentMillis + ((Minutes *60) *1000);
powerOn();
}
display_text("S " + String(Minutes));
delay_gui(1000);
}
void handleSleep(unsigned long intervall, unsigned long currentMillis){
if(time_on < 0){
return;
}
else if (currentMillis > time_on)
{
powerOff();
time_on = -1;
minutes_sleep = -1;
}
}
void switch_input(){
int currentIn = digitalRead(outInput);
if(currentIn == LOW){
switch_in(true);
}
else{
switch_radio(true);
}
}
void switch_radio(bool display_switch){
digitalWrite(outInput, LOW);
if(display_switch){
display_text("Radio");
delay_gui(500);
}
}
void switch_in(bool display_switch){
digitalWrite(outInput, HIGH);
if(display_switch){
display_text("In");
delay_gui(500);
}
}
void toggle_power(){
int currentState = digitalRead(outPower);
if (currentState == LOW){
powerOff();
}
else{
powerOn();
}
}
void powerOff(){
time_on = -1;
int currentState = digitalRead(outPower);
if (currentState != HIGH){
Serial.println("OFF");
digitalWrite(outPower, HIGH);
display_text("OFF");
delay_gui(1000);
}
switch_in(false);
}
void powerOn(){
int currentState = digitalRead(outPower);
if (currentState != LOW){
Serial.println("ON");
digitalWrite(outPower, LOW);
display_text("ON");
delay_gui(1000);
}
}