From d12fbe1eda09ea3444612bca7769bf7f60375068 Mon Sep 17 00:00:00 2001 From: ajk1e20 <ajk1e20@soton.ac.uk> Date: Thu, 12 May 2022 20:05:34 +0000 Subject: [PATCH] Upload New File --- alarm/alarm.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 alarm/alarm.c diff --git a/alarm/alarm.c b/alarm/alarm.c new file mode 100644 index 0000000..b5a47f0 --- /dev/null +++ b/alarm/alarm.c @@ -0,0 +1,90 @@ +/** + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "pico/stdlib.h" +#include "lib/fonts.h" +#include "lib/st7735.h" + +int main() { + + //TODO: Create uints for the pins you are using + const uint button = 20; + const uint button1 = 21; + const uint button2 = 22; + bool start = false; + + //TODO: Initialise the pins + gpio_init(button); + gpio_init(button1); + gpio_init(button2); + + + //TODO: Set the pins to in/out + gpio_set_dir(button, GPIO_IN); + gpio_set_dir(button1, GPIO_IN); + gpio_set_dir(button2, GPIO_IN); + + + //TODO: Initialise ST7735 + ST7735_Init(); + ST7735_FillScreen(ST7735_BLACK); + + while (true) { + //TODO: Start screen and create variables + char tString[5]; + int timer = 0; + int timerSec = 0; + sprintf(tString, "%2d: %2d", timer, timerSec); + + + 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 + if (!gpio_get(button)) { + timer = timer + 1; + sprintf(tString, "%2d: %2d", timer, timerSec); + } + if (!gpio_get(button1)) { + timer = timer - 1; + sprintf(tString, "%2d: %2d", timer, timerSec); + } + if (!gpio_get(button2)) { + start = true; + } + sprintf(tString, "%2d: %2d", timer, timerSec); + ST7735_WriteString(5, 45, tString, Font_16x26, ST7735_WHITE, ST7735_BLACK); + } + while (start) { + //TODO: Display the countdown timer going down, in minutes and seconds + if (timer == 0 && timerSec == 0) { + start = false; + } + if (timerSec == 0) { + timer--; + timerSec = 59; + } + timerSec--; + sleep_ms(1000); + + ST7735_WriteString(5, 45, tString, Font_16x26, ST7735_WHITE, ST7735_BLACK); + } + while (true) { + //TODO: Display a message to alert the user the timer is done (possibly flashing) which stops when a button is pressed + ST7735_WriteString(5, 45, "DONE", Font_16x26, ST7735_WHITE, ST7735_BLACK); + if (!gpio_get(button)) + { + break; + } + if (!gpio_get(button1)) + { + break; + } + if (!gpio_get(button2)) + { + break; + } + } + } +} -- GitLab