Skip to content
Snippets Groups Projects
Commit d12fbe1e authored by ajk1e20's avatar ajk1e20
Browse files

Upload New File

parent 5a3d1d07
No related branches found
No related tags found
No related merge requests found
/**
* 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;
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment