Skip to content
Snippets Groups Projects
Commit 03981bbb authored by jma1g20's avatar jma1g20
Browse files

Merge branch 'jma1g20-main-patch-03863' into 'main'

Update alarm.c

See merge request !1
parents d4e9401e 8dbdc88f
No related branches found
No related tags found
1 merge request!1Update alarm.c
...@@ -13,124 +13,33 @@ int main() { ...@@ -13,124 +13,33 @@ int main() {
#warning blink example requires a board with a regular LED #warning blink example requires a board with a regular LED
#else #else
//TODO: Create uints for the pins you are using //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 //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 //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 //TODO: Initialise ST7735
ST7735_Init();
while (true) { while (true) {
//TODO: Start screen and create variables //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) { 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 //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) { while (start) {
//TODO: Display the countdown timer going down, in minutes and seconds //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) { while (true) {
//TODO: Display a message to alert the user the timer is done (possibly flashing) which stops when a button is pressed //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 #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment