This repository has been archived on 2022-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
AtTiny_alarm_clock/main_old.c

101 lines
2.3 KiB
C

/*
* GccApplication1.c
*
* Created: 10.07.2018 19:39:28
* Author : dozed
*/
#define button1 1234
#define button2 5678
#define button3 whatever
typedef enum {CLOCK_INIT = 0, CLOCK_IDLE, CLOCK_ALARM, CLOCK_STOPWATCH_RUNNING, CLOCK_STOPWATCH_STOPPED, CLOCK_STOPWATCH_NOT_SET, CLOCK_USER_INPUT, CLOCK_SET_TIME} clock_state_e;
clock_state_e clock_old_state = NULL;
clock_state_e clock_state = CLOCK_INIT;
clock_state_e clock_new_state = CLOCK_INIT;
int counter = 0; //the counter variable that is being set by the interrupt
//variables for the alarm
bool alarm_active = false;
bool alarm_triggered = false;
int alarm_time = 0;
//variables for the stopwatch
bool stopwatch_running = false;
bool stopwatch_set = false
int stopwatch_started = 0;
int stopwatch_stopped = 0;
//other variables
int user_input = 0; //variable to store user input
int current_time = 0;
int main(void)
{
//-----------INIT----------------
//SETUP PINS (needs to be done)
//attach interrupt (needs to be done)
//-----------END INIT------------
while (1)
{
timer_state = timer_new_state;
switch(clock_state){
case CLOCK_INIT:
//do some init stuff...
lcd.init(); //I know, it's just c but I don't care
//INIT done -> change to IDLE
clock_new_state = CLOCK_IDLE;
break;
case CLOCK_IDLE:
//IDLE MODE
//print the IDLE Screen
lcd.goto(0,0);
lcd.print(counter /*do some claculations*/);
lcd.goto(0,1);
lcd.print("< current time >");
//check buttons
if(button_pressed(1)){
timer_new_state = CLOCK_ALARM;
}
else if(button_pressed(2){
//do something
}
else if(button_pressed(3)){
//do something
}
case CLOCK_ALARM:
//CLOCK ALARM
//check if the alarm time was set
if(user_input == 0){
alarm_time = user_input;
user_input = 0;
}
if(alarm_active){
lcd.goto(0,0);
lcd.print(current_time);
lcd.goto(0,1);
lcd.print("alarm >");
}
}
//do some other stuff (like checking if an alarm has been triggered)
}
}
bool button_pressed(int button_number)
{
bool button_state = /*check the state of the button here*/;
return(button_state);
}