Skip to content

Commit

Permalink
Update examples for API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
philipbl committed Jan 15, 2025
1 parent cb1478f commit 0ca359b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
2 changes: 0 additions & 2 deletions y-board-v3/audio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ bool played_after_stopping = false;
bool played_after_done = false;

void loop() {
Yboard.loop_speaker();

// Uncomment this to stop the audio after 5 seconds to test the stop functionality
// and then start mary had a little lamb again 3 seconds later
//
Expand Down
18 changes: 5 additions & 13 deletions y-board-v3/light_dial_game/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ void play_bad_guess();
void play_win();
int filter(int value);
Color map_to_color(int value, int min_value, int max_value);
void delay_with_audio(int ms);
void wait_for_audio();

const int code_length = 5;
Expand Down Expand Up @@ -113,7 +112,7 @@ void play_correct_guess() {
if (!Yboard.play_sound_file_background(file_name)) {
Yboard.play_notes_background("V2 T240 CE");
}
delay_with_audio(100);
delay(100);
Yboard.set_all_leds_color(0, 255, 0);
wait_for_audio();
Yboard.set_all_leds_color(0, 0, 0);
Expand All @@ -123,7 +122,7 @@ void play_bad_guess() {
if (!Yboard.play_sound_file_background("/light_game/sm64_thwomp.wav")) {
Yboard.play_notes_background("V2 T240 AC");
}
delay_with_audio(100);
delay(100);
Yboard.set_all_leds_color(255, 0, 0);
wait_for_audio();
Yboard.set_all_leds_color(0, 0, 0);
Expand All @@ -136,11 +135,11 @@ void play_win() {

for (int i = 1; i <= Yboard.led_count; i++) {
Yboard.set_led_color(i, 0, 255, 0);
delay_with_audio(100);
delay(100);
}

Yboard.set_all_leds_color(0, 0, 0);
delay_with_audio(250);
delay(250);
Yboard.set_all_leds_color(0, 255, 0);

wait_for_audio();
Expand All @@ -167,15 +166,8 @@ Color map_to_color(int value, int min_value, int max_value) {
return color;
}

void delay_with_audio(int ms) {
unsigned long start_time = millis();
while (millis() - start_time < ms) {
Yboard.loop_speaker();
}
}

void wait_for_audio() {
while (Yboard.is_audio_playing()) {
Yboard.loop_speaker();
delay(1);
}
}

0 comments on commit 0ca359b

Please sign in to comment.