// Source :: Lab 5
// Description :: Lab 5 - Counting in Octal & Hex
// Programmed by :: Douglas Vieira Ferreira / 03-17-2024
/*
The assignment involves modifying the chapter 11 of the starter kit that shows values on the LCD Screen.
The numbers incremets its values over time, displaying numbers in diferrent numerical bases.
*/
#include <LiquidCrystal.h>
// Initialize the LCD library with the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Global variable for the counter
int counter01 = 0;
void setup() {
// Set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}
void loop() {
int sensorValue = analogRead(A0); // Read the potentiometer value
int base = map(sensorValue, 0, 1023, 0, 4); // Map the value to 0-3 for base selection
// Clear the LCD screen before displaying the new value
lcd.clear();
// Depending on the potentiometer's position, display the counter in different bases
switch (base) {
case 0: // Decimal
lcd.print("Dec: ");
lcd.print(counter01);
break;
case 1: // Binary
lcd.print("Bin: ");
lcd.print(counter01, BIN);
break;
case 2: // Octal
lcd.print("Oct: ");
lcd.print(counter01, OCT);
break;
case 3: // Hexadecimal
lcd.print("Hex: ");
lcd.print(counter01, HEX);
break;
}
// Increment the counter and reset if it exceeds 255
counter01++;
if (counter01 > 255) {
counter01 = 0;
}
// Wait for a second before the next update
delay(1000);
}