Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Pi Pico Piano
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
ebp1g21
Pi Pico Piano
Commits
524befe3
Commit
524befe3
authored
2 years ago
by
ebp1g21
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
994fdf6a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
stub.c
+66
-0
66 additions, 0 deletions
stub.c
with
66 additions
and
0 deletions
stub.c
0 → 100644
+
66
−
0
View file @
524befe3
#include
"pico/stdlib.h"
#include
"hardware/pwm.h"
#include
"hardware/clocks.h"
#define BUZZER_PIN 18 // This is both the buzzer and audio jack (just in case you have anything to plug into it)
#define BUTTON_1_PIN 20
#define BUTTON_2_PIN 21
#define BUTTON_3_PIN 22
#define FREQ_1 261.6256f
#define FREQ_2 293.6648f
#define FREQ_3 329.6276f
/**
* A method for playing a note on the speaker.
* @param frequency Frequency of the note in Hz.
*/
void
playNote
(
float
frequency
)
{
// TODO - make a note of that frequency play on the buzzer
}
/**
* A method for silencing the speaker.
*/
void
playNothing
()
{
// TODO - make the buzzer be silent
}
/**
* A method for handling GPIO events.
* @param gpio GPIO Number.
* @param event_mask Which events will cause an interrupt. See gpio_irq_level for details.
*/
void
handleEvent
(
uint
gpio
,
uint32_t
event_mask
)
{
// TODO - link the events to the play methods
}
int
main
()
{
stdio_init_all
();
// Setting up the buzzer
gpio_set_function
(
BUZZER_PIN
,
GPIO_FUNC_PWM
);
// Linking the buttons to the event handler
gpio_set_irq_enabled_with_callback
(
BUTTON_1_PIN
,
GPIO_IRQ_EDGE_FALL
,
true
,
&
handleEvent
);
gpio_set_irq_enabled_with_callback
(
BUTTON_2_PIN
,
GPIO_IRQ_EDGE_FALL
,
true
,
&
handleEvent
);
gpio_set_irq_enabled_with_callback
(
BUTTON_3_PIN
,
GPIO_IRQ_EDGE_FALL
,
true
,
&
handleEvent
);
gpio_set_irq_enabled_with_callback
(
BUTTON_1_PIN
,
GPIO_IRQ_EDGE_RISE
,
true
,
&
handleEvent
);
gpio_set_irq_enabled_with_callback
(
BUTTON_2_PIN
,
GPIO_IRQ_EDGE_RISE
,
true
,
&
handleEvent
);
gpio_set_irq_enabled_with_callback
(
BUTTON_3_PIN
,
GPIO_IRQ_EDGE_RISE
,
true
,
&
handleEvent
);
// Main Program Loop
while
(
true
)
{
tight_loop_contents
();
}
return
0
;
// This will never be reached
}
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