From 3326266fd29227fdd58a20cd4d02d219336e1873 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Fri, 17 Feb 2017 12:04:00 +0100 Subject: [PATCH] Added ability to choose a song from a list, using two new modes and a play button and pause button functionality on the left and right buttons. --- BicycleControl.ino | 48 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/BicycleControl.ino b/BicycleControl.ino index c07258b..8cf8055 100644 --- a/BicycleControl.ino +++ b/BicycleControl.ino @@ -41,7 +41,7 @@ U8X8_SSD1306_128X64_NONAME_4W_SW_SPI screen(OLED_CLK, OLED_MOSI, OLED_CS, OLED_D #define IN_mode 17 #define IN_left 18 #define IN_right 19 -#define MODE_MAX 2 +#define MODE_MAX 3 //Global variables //Shift register buffer. @@ -180,6 +180,18 @@ short skyrim[] = { NOTE_REST, 8 }; +//Song variables. +short songCount = 2; +short currentSong = 0; +short* songs[] = { + skyrim, + beep1, +}; +String songNames[] = { + "Skyrim", + "Beep1", +}; + //-------------------| //GRAPHICS FUNCTIONS:| //-------------------| @@ -235,6 +247,15 @@ void drawModeStatus() { screen.print((int)mode); } +void drawSongStatus() { + screen.setFont(u8x8_font_artossans8_r); + screen.setInverseFont(0); + screen.setCursor(6, 4); + screen.print(" "); + screen.setCursor(6, 4); + screen.print(songNames[currentSong]); +} + //-------------------| //STARTUP FUNCTIONS: | //-------------------| @@ -354,6 +375,18 @@ void updateInputs() { case 1: if (!blinkerLeft) activateBlinker(0); break; + case 2: + if (currentSong == 0) { + currentSong = songCount - 1; + } + else { + currentSong--; + } + drawSongStatus(); + break; + case 3: + isPlaying = false; + break; } //Serial.println("Left pressed."); } @@ -368,6 +401,17 @@ void updateInputs() { case 1: if (!blinkerRight) activateBlinker(1); break; + case 2: + if (currentSong == songCount - 1) { + currentSong = 0; + } else { + currentSong++; + } + drawSongStatus(); + break; + case 3: + playSequence(songs[currentSong]); + break; } //Serial.println("Right pressed."); } @@ -522,8 +566,8 @@ void setup() { startupPeripherals(); startupScreen(); drawMainScreen(); + drawSongStatus(); updateAll(); - playSequence(beep1); } void loop() {