Files
Licht_Wecker/LichtWecker/pinInput.ino
2018-04-17 11:10:52 +02:00

110 lines
2.0 KiB
C++

//Test if button pressed
void test_pin(){
handle_Time_switch();
handle_Set_switch();
handle_Alarm_switch();
}
//If Alarm switch pressed
void handle_Alarm_switch(){
int state = digitalRead(pinAlarm);
if(state == LOW && setItem == 0) {
int presstime = get_pin_delay(pinAlarm);
if (presstime > 10){
set_alarm_item();
delay(200);
wait_to_release(pinAlarm);
}
else{
if (alarm_started == true)
{
stop_alarm();
}
else{
//Delete Message
if(message_text != ""){
message_text = "";
}
else{
switch_alarm_mode();
}
}
delay(200);
}
}
else if(state == LOW){
set_alarm_item();
delay(200);
}
}
//If Set switch pressed
void handle_Set_switch(){
int state = digitalRead(pinSet);
if (state == LOW && setItem > 0){
set_time();
delay(200);
}
else if(state == LOW && setItem == 0) {
int presstime = get_pin_delay(pinSet);
if (presstime > 10){
//Do some Stuff here
delay(200);
wait_to_release(pinSet);
}
else{
switch_lamp();
delay(200);
}
}
}
//If Time switch pressed
void handle_Time_switch(){
int state = digitalRead(pinTime);
if(state == LOW && setItem == 0) {
int presstime = get_pin_delay(pinTime);
if (presstime > 10){
switch_set_item();
delay(200);
wait_to_release(pinTime);
}
else{
//toggle_power();
toggle_bg_light();
}
}
else if(state == LOW){
switch_set_item();
delay(200);
}
}
//Helper for long-press
int get_pin_delay(int pin){
int state = digitalRead(pin);
int delay_count = 0;
while(state == LOW && delay_count < 11)
{
state = digitalRead(pin);
update_display();
delay(100);
delay_count = delay_count +1;
}
return delay_count;
}
//Helper for long-press
void wait_to_release(int pin){
int state = digitalRead(pin);
while(state == LOW)
{
state = digitalRead(pin);
update_display();
delay(100);
}
}