Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Comp2215 Pico 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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jma1g20
Comp2215 Pico Alarm
Commits
03981bbb
Commit
03981bbb
authored
3 years ago
by
jma1g20
Browse files
Options
Downloads
Plain Diff
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
!1
Update alarm.c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
alarm.c
+8
-99
8 additions, 99 deletions
alarm.c
with
8 additions
and
99 deletions
alarm.c
+
8
−
99
View file @
03981bbb
...
@@ -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
...
...
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