summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Bryant <jbryant0653@floridapoly.edu>2024-04-21 17:46:59 -0400
committerJoseph Bryant <jbryant0653@floridapoly.edu>2024-04-21 17:48:09 -0400
commit77e29b942cf316fb809efcbed2c2e9245f6ed820 (patch)
treed8e5a9dcf5266a7d4605b8ed16bfc29c92022716
parent0c484fcae021309d5ebaa409197c28c51885dac3 (diff)
Made button A5 work and shifting random characters
-rw-r--r--lcd.c48
1 files changed, 36 insertions, 12 deletions
diff --git a/lcd.c b/lcd.c
index d5da485..2257196 100644
--- a/lcd.c
+++ b/lcd.c
@@ -2,6 +2,7 @@
2#define F_CPU 16000000UL // THE CPU FREQUENCY 2#define F_CPU 16000000UL // THE CPU FREQUENCY
3#include <util/delay.h> //delay header 3#include <util/delay.h> //delay header
4#include <avr/interrupt.h> //interrupt header 4#include <avr/interrupt.h> //interrupt header
5#include <stdlib.h>
5 6
6#define LCD_DPRT PORTD //LCD DATA PORT 7#define LCD_DPRT PORTD //LCD DATA PORT
7#define LCD_DDDR DDRD //LCD DATA DDR 8#define LCD_DDDR DDRD //LCD DATA DDR
@@ -139,19 +140,41 @@ ISR(PCINT1_vect) {
139} 140}
140 141
141void displaySerialData() { 142void displaySerialData() {
143 char circularBuffer[16];
144 static int bufferIndex = 0;
145
142 lcd_clear(); 146 lcd_clear();
143 lcd_gotoxy(1, 1); 147 lcd_gotoxy(1, 1);
144 while (!(buttonState == 5)) { 148 lcd_print("KindaGood");
145 char newData = getSerialData(); 149 while ((PINC & _BV(5)) == 0) {
146 if (newData != '\0') { 150 char randomValue = '0' + (rand() % 10);
147 // Add new data to the left side of line 1 of the LCD 151
148 // Push existing data to the right 152 if (bufferIndex == 16) {
149 // Display on LCD 153 // Remove the first value and shift other values down
154 for (int i = 0; i < 16 - 1; i++) {
155 circularBuffer[i] = circularBuffer[i + 1];
156 }
157 // Add the new value at the end
158 circularBuffer[16 - 1] = randomValue;
159 } else {
160 // Add the new value to the buffer
161 circularBuffer[bufferIndex++] = randomValue;
162 }
163
164 lcd_clear();
165 lcd_gotoxy(1, 1);
166 for (int i = 0; i < 16; i++) {
167 char singleChar[2] = {circularBuffer[i], '\0'};
168 lcd_print(singleChar); // Print the single character
150 } 169 }
151 _delay_ms(100); // Adjust delay as needed 170
171 _delay_ms(1000);
152 } 172 }
173 lcd_clear();
153} 174}
154 175
176
177
155void displayNotes() { 178void displayNotes() {
156 lcd_clear(); 179 lcd_clear();
157 lcd_gotoxy(1, 1); 180 lcd_gotoxy(1, 1);
@@ -177,16 +200,17 @@ int main(void) {
177 while (1) { 200 while (1) {
178 // Check button state and perform actions accordingly 201 // Check button state and perform actions accordingly
179 if (buttonState == 5) { 202 if (buttonState == 5) {
180 lcd_clear(); 203 lcd_gotoxy(1,1);
181 lcd_gotoxy(1,1); 204 lcd_print("good");
182 lcd_print("Button A5 Works"); 205 displaySerialData();
183 _delay_ms(100); 206 buttonState = 0;
184 //displaySerialData(); 207
185 } else if (buttonState == 4) { 208 } else if (buttonState == 4) {
186 lcd_clear(); 209 lcd_clear();
187 lcd_gotoxy(1,2); 210 lcd_gotoxy(1,2);
188 lcd_print("Button A4 Works"); 211 lcd_print("Button A4 Works");
189 _delay_ms(100); 212 _delay_ms(100);
213 buttonState = 0;
190 //displayNotes(); 214 //displayNotes();
191 } 215 }
192 } 216 }