/*
* Erik Hansen
* March 19, 2023
* Lab 5 Project
*/
// include the library code:
#include <LiquidCrystal.h>
// Declaration
LiquidCrystal lcd(12, 11, 10, 9, 8, 7); // LCD Pins (7-10 = Data 4-7, 11-12 = Enable/Read)
int potPin = A0;
// Values/Variables
int Counter01 = 0; //
int potValue = 0;
int outputValue = 0;
void setup() {
// Set up LCD (rows/columns)
lcd.begin(16, 2);
// Set up the Potentiometer
pinMode(potPin, INPUT);
}
void loop() {
// Increment Counter01
Counter01++;
// Potentiometer
potValue = analogRead(potPin);
outputValue = map(potValue, 0, 1023, 0, 3);
// Check if Counter01 is greater than 255, if so reset to 0
if (Counter01 > 255) {
Counter01 = 0;
}
// Clear LCD screen
lcd.setCursor(0, 1); // Move to line 2
lcd.clear();
lcd.setCursor(0, 0); // Move to line 1
lcd.clear();
// Switch case to check what to display
switch (outputValue) {
case 0: // Binary
lcd.print("Binary: ");
lcd.setCursor(0, 1); // Move to line 2
lcd.print(Counter01, BIN);
break;
case 1: // Octal
lcd.print("Octal: ");
lcd.setCursor(0, 1); // Move to line 2
lcd.print(Counter01, OCT);
break;
case 2: // Hex
lcd.print("Hex: ");
lcd.setCursor(0, 1); // Move to line 2
lcd.print(Counter01, HEX);
break;
}
// Delay
delay(250);
}