diff options
| -rw-r--r-- | lcd.c | 19 |
1 files changed, 13 insertions, 6 deletions
| @@ -23,6 +23,8 @@ char notesBuffer[NOTES_BUFFER_SIZE]; | |||
| 23 | int serialIndex = 0; | 23 | int serialIndex = 0; |
| 24 | int notesIndex = 0; | 24 | int notesIndex = 0; |
| 25 | volatile int buttonState = 0; // Holds the state of all buttons | 25 | volatile int buttonState = 0; // Holds the state of all buttons |
| 26 | unsigned char songBuffer[1024]; | ||
| 27 | int count = 0; | ||
| 26 | 28 | ||
| 27 | void | 29 | void |
| 28 | usart_init(void) | 30 | usart_init(void) |
| @@ -167,17 +169,18 @@ ISR(PCINT1_vect) { | |||
| 167 | void displayNotes() { | 169 | void displayNotes() { |
| 168 | char circularBuffer[16]; | 170 | char circularBuffer[16]; |
| 169 | static int bufferIndex = 0; | 171 | static int bufferIndex = 0; |
| 170 | 172 | ||
| 171 | lcd_clear(); | 173 | lcd_clear(); |
| 172 | lcd_gotoxy(6, 2); | 174 | lcd_gotoxy(6, 2); |
| 173 | lcd_print("PLAYING"); | 175 | lcd_print("PLAYING"); |
| 174 | _delay_ms(1000); | 176 | _delay_ms(1000); |
| 175 | lcd_clear(); | 177 | lcd_clear(); |
| 176 | _delay_ms(1000); | 178 | _delay_ms(1000); |
| 177 | while (buttonState == 4) { | 179 | for(int k = 0; k < count) { |
| 178 | char randomValue = getNote(); | 180 | unsigned char randomValue = songBuffer[k]; |
| 179 | 181 | ||
| 180 | if (bufferIndex == 16) { | 182 | if (bufferIndex == 16) { |
| 183 | |||
| 181 | // Remove the first value and shift other values down | 184 | // Remove the first value and shift other values down |
| 182 | for (int i = 0; i < 16 - 1; i++) { | 185 | for (int i = 0; i < 16 - 1; i++) { |
| 183 | circularBuffer[i] = circularBuffer[i + 1]; | 186 | circularBuffer[i] = circularBuffer[i + 1]; |
| @@ -199,8 +202,9 @@ void displayNotes() { | |||
| 199 | lcd_print("PLAYING"); | 202 | lcd_print("PLAYING"); |
| 200 | } | 203 | } |
| 201 | 204 | ||
| 202 | //_delay_ms(1000); | 205 | _delay_ms(500); |
| 203 | } | 206 | } |
| 207 | buttonState = 0; | ||
| 204 | bufferIndex = 0; | 208 | bufferIndex = 0; |
| 205 | lcd_clear(); | 209 | lcd_clear(); |
| 206 | } | 210 | } |
| @@ -216,7 +220,10 @@ void displaySerialData() { | |||
| 216 | lcd_clear(); | 220 | lcd_clear(); |
| 217 | _delay_ms(1000); | 221 | _delay_ms(1000); |
| 218 | while (buttonState == 5) { | 222 | while (buttonState == 5) { |
| 219 | char randomValue = getNote(); | 223 | unsigned char randomValue = getNote(); |
| 224 | count = 0; | ||
| 225 | songBuffer[count] = randomValue; | ||
| 226 | count++; | ||
| 220 | 227 | ||
| 221 | if (bufferIndex == 16) { | 228 | if (bufferIndex == 16) { |
| 222 | // Remove the first value and shift other values down | 229 | // Remove the first value and shift other values down |
| @@ -257,7 +264,7 @@ void displayPiano() { | |||
| 257 | lcd_clear(); | 264 | lcd_clear(); |
| 258 | _delay_ms(1000); | 265 | _delay_ms(1000); |
| 259 | while (buttonState == 0) { | 266 | while (buttonState == 0) { |
| 260 | char randomValue = getNote(); | 267 | unsigned char randomValue = getNote(); |
| 261 | 268 | ||
| 262 | if (bufferIndex == 16) { | 269 | if (bufferIndex == 16) { |
| 263 | // Remove the first value and shift other values down | 270 | // Remove the first value and shift other values down |
