diff --git a/alarm.c b/alarm.c index 5d1b762afeeb76a457a8b60348881317772dea34..4525ab7108294295c97097fc95bb8c8dd0882ab6 100644 --- a/alarm.c +++ b/alarm.c @@ -13,124 +13,33 @@ int main() { #warning blink example requires a board with a regular LED #else //TODO: Create uints for the pins you are using - const uint LED_PIN = PICO_DEFAULT_LED_PIN; - const uint BUTTON_PIN_1 = 20; - const uint BUTTON_PIN_2 = 21; - const uint BUTTON_PIN_3 = 22; + //TODO: Initialise the pins - gpio_init(LED_PIN); - gpio_init(BUTTON_PIN_1); - gpio_init(BUTTON_PIN_2); - gpio_init(BUTTON_PIN_3); + //TODO: Set the pins to in/out - gpio_set_dir(LED_PIN, GPIO_OUT); - gpio_set_dir(BUTTON_PIN_1, GPIO_IN); - gpio_set_dir(BUTTON_PIN_2, GPIO_IN); - gpio_set_dir(BUTTON_PIN_3, GPIO_IN); + //TODO: Initialise ST7735 - ST7735_Init(); + while (true) { //TODO: Start screen and create variables - ST7735_FillScreen(ST7735_BLACK); - ST7735_WriteString(5, 20, "HI", Font_16x26, ST7735_WHITE, ST7735_BLACK); - - sleep_ms(500); - gpio_put(LED_PIN, 1); - sleep_ms(3000); - gpio_put(LED_PIN, 0); - - int minutes = 0; - char minutesString[5]; - int seconds = 0; - char secondsString[5]; - bool start = false; + while (!start) { //TODO: Display screen with current time, and set up each of the buttons to add a minute, remove a minute and start the timer - ST7735_FillScreen(ST7735_BLACK); - sprintf(minutesString, "%d", minutes); - ST7735_WriteString(5, 20, minutesString, Font_16x26, ST7735_WHITE, ST7735_BLACK); - ST7735_WriteString(5, 45, "Min", Font_16x26, ST7735_WHITE, ST7735_BLACK); - ST7735_WriteString(5, 70, "0", Font_16x26, ST7735_WHITE, ST7735_BLACK); - ST7735_WriteString(5, 95, "Sec", Font_16x26, ST7735_WHITE, ST7735_BLACK); - if (!gpio_get(BUTTON_PIN_1)) { - gpio_put(LED_PIN, 1); - minutes = minutes + 1; - sleep_ms(200); - } - else - { - gpio_put(LED_PIN, 0); - } - if (!gpio_get(BUTTON_PIN_2)) { - gpio_put(LED_PIN, 1); - if (minutes != 0) { - minutes = minutes - 1; - } - sleep_ms(200); - } - else - { - gpio_put(LED_PIN, 0); - } - if (!gpio_get(BUTTON_PIN_3)) - { - start = true; - break; - } + } while (start) { //TODO: Display the countdown timer going down, in minutes and seconds - ST7735_FillScreen(ST7735_BLACK); - sprintf(minutesString, "%d", minutes); - sprintf(secondsString, "%d", seconds); - ST7735_WriteString(5, 20, minutesString, Font_16x26, ST7735_WHITE, ST7735_BLACK); - ST7735_WriteString(5, 45, "Min", Font_16x26, ST7735_WHITE, ST7735_BLACK); - ST7735_WriteString(5, 70, secondsString, Font_16x26, ST7735_WHITE, ST7735_BLACK); - ST7735_WriteString(5, 95, "Sec", Font_16x26, ST7735_WHITE, ST7735_BLACK); - sleep_ms(1000); - if (seconds == 0) { - if (minutes == 0) { - start = false; - break; - } - else { - seconds = 59; - minutes = minutes - 1; - } - } - else { - seconds = seconds - 1; - } + } while (true) { //TODO: Display a message to alert the user the timer is done (possibly flashing) which stops when a button is pressed - ST7735_FillScreen(ST7735_BLACK); - ST7735_WriteString(5, 20, "DONE", Font_16x26, ST7735_WHITE, ST7735_BLACK); - ST7735_WriteString(5, 45, "DONE", Font_16x26, ST7735_WHITE, ST7735_BLACK); - ST7735_WriteString(5, 70, "DONE", Font_16x26, ST7735_WHITE, ST7735_BLACK); - ST7735_WriteString(5, 95, "DONE", Font_16x26, ST7735_WHITE, ST7735_BLACK); - sleep_ms(200); - if (gpio_get(BUTTON_PIN_1)) { - break; - } - if (gpio_get(BUTTON_PIN_2)) { - break; - } - if (gpio_get(BUTTON_PIN_3)) { - break; - } - ST7735_FillScreen(ST7735_WHITE); - ST7735_WriteString(5, 20, "DONE", Font_16x26, ST7735_BLACK, ST7735_WHITE); - ST7735_WriteString(5, 45, "DONE", Font_16x26, ST7735_BLACK, ST7735_WHITE); - ST7735_WriteString(5, 70, "DONE", Font_16x26, ST7735_BLACK, ST7735_WHITE); - ST7735_WriteString(5, 95, "DONE", Font_16x26, ST7735_BLACK, ST7735_WHITE); - sleep_ms(200); + } } #endif