Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Alarm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ajk1e20
Alarm
Commits
d12fbe1e
Commit
d12fbe1e
authored
3 years ago
by
ajk1e20
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
5a3d1d07
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
alarm/alarm.c
+90
-0
90 additions, 0 deletions
alarm/alarm.c
with
90 additions
and
0 deletions
alarm/alarm.c
0 → 100644
+
90
−
0
View file @
d12fbe1e
/**
* 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
;
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment