From: Advaith Menon <83835839+advaithm582@users.noreply.github.com> Date: Fri, 26 Sep 2025 21:24:44 +0000 (-0400) Subject: Finish Lab 4 X-Git-Url: https://git.devinivas.org/?a=commitdiff_plain;h=c366ff5b41d33f5d66a525175e7cd6a249d5d9bd;p=gt-ece4180-lab02.git Finish Lab 4 * uLCD now moves with nav switch --- diff --git a/04-uLCDNavSwitch/04-uLCDNavSwitch.ino b/04-uLCDNavSwitch/04-uLCDNavSwitch.ino index 74f966a..e442bd6 100644 --- a/04-uLCDNavSwitch/04-uLCDNavSwitch.ino +++ b/04-uLCDNavSwitch/04-uLCDNavSwitch.ino @@ -1,6 +1,126 @@ +/** + * @file 04-uLCDNavSwitch.ino + * @author Advaith Menon, Anish Gajula, Lila Phonekeo + * @brief Control a ball on the uLCD with a Nav Switch. + */ + +#define DOWNPIN 18 +#define LEFTPIN 19 +#define RIGHTPIN 9 +#define FIREPIN 20 +#define UPPIN 21 +#define DEFAULT_VCC 22 +#define RESETLINE 23 + +#define C_DEFAULT 0 +#define DIR_N 0x01 +#define DIR_X 0x02 +#define DIR_W 0x04 +#define DIR_S 0x08 +#define DIR_E 0x10 + +#define CIR_STARTX 64 +#define CIR_STARTY 64 +#define CIR_RADIUS 20 + +#define MOTION_XRANGE 128 +#define MOTION_YRANGE 128 +#define MOTION_DELTA 5 + +#define PIN_TX 16 +#define PIN_RX 17 + +#define DIR_NE (DIR_N | DIR_E) +#define DIR_NW (DIR_N | DIR_W) +#define DIR_SE (DIR_S | DIR_E) +#define DIR_SW (DIR_S | DIR_W) + + +#include +#include "Goldelox_Serial_4DLib.h" +#include "Goldelox_Const4D.h" + +Goldelox_Serial_4DLib Display(&Serial); + +uint8_t cir_x; +uint8_t cir_y; void setup() { + Serial.begin(9600); + /* setup nav switch + to be high */ + pinMode(DEFAULT_VCC, OUTPUT); + digitalWrite(DEFAULT_VCC, HIGH); + + + /* set up rest of the device */ + pinMode(DOWNPIN, INPUT); + pinMode(LEFTPIN, INPUT); + pinMode(RIGHTPIN, INPUT); + pinMode(FIREPIN, INPUT); + pinMode(UPPIN, INPUT); + pinMode(RESETLINE, OUTPUT); + + digitalWrite(RESETLINE, 0); // Reset the Display via D4 + delay(500); + digitalWrite(RESETLINE, 1); // unReset the Display via D4 + delay(500); + + // Display.setbaudWait(BAUD_9600); + Serial.begin(9600, SERIAL_8N1, PIN_RX, PIN_TX); + // Display.setbaudWait(BAUD_9600); + Display.gfx_Cls(); + cir_x = CIR_STARTX; + cir_y = CIR_STARTY; + Display.gfx_CircleFilled(cir_x, cir_y, CIR_RADIUS, BLUE); } void loop() { + uint8_t i; + + + /* get the input value as bit flags */ + i = C_DEFAULT; + if (digitalRead(DOWNPIN) == LOW) + i |= DIR_S; + if (digitalRead(LEFTPIN) == LOW) + i |= DIR_W; + if (digitalRead(RIGHTPIN) == LOW) + i |= DIR_E; + if (digitalRead(FIREPIN) == LOW) + i |= DIR_X; + if (digitalRead(UPPIN) == LOW) + i |= DIR_N; + + if (i) + Display.gfx_CircleFilled(cir_x, cir_y, CIR_RADIUS, BLACK); + + if (i & DIR_N) cir_y = (cir_y + MOTION_DELTA > MOTION_YRANGE - CIR_RADIUS) + ? cir_y + : cir_y + MOTION_DELTA; + if (i & DIR_E) cir_x = (cir_x + MOTION_DELTA > MOTION_XRANGE - CIR_RADIUS) + ? cir_x + : cir_x + MOTION_DELTA; + if (i & DIR_W) cir_x = (cir_x - MOTION_DELTA <= CIR_RADIUS) + ? cir_x + : cir_x - MOTION_DELTA; + if (i & DIR_S) cir_y = (cir_y - MOTION_DELTA <= CIR_RADIUS) + ? cir_y + : cir_y - MOTION_DELTA; + + /* draw circle */ + if (i) + Display.gfx_CircleFilled(cir_x, cir_y, CIR_RADIUS, BLUE); + + /* update ball position */ + /* + Display.txt_MoveCursor(5,3); + Display.putstr(" "); + Display.txt_MoveCursor(5,3); + if (i & DIR_N) Display.putstr("N"); + if (i & DIR_E) Display.putstr("E"); + if (i & DIR_S) Display.putstr("S"); + if (i & DIR_W) Display.putstr("W"); + if (i & DIR_X) Display.putstr("X"); + */ + }