Skip to content
Snippets Groups Projects
Commit 524befe3 authored by ebp1g21's avatar ebp1g21
Browse files

Upload New File

parent 994fdf6a
Branches
No related tags found
No related merge requests found
stub.c 0 → 100644
#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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment