/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: "Speedometer Interface"
- Source Code compiled for: Arduino Uno
- Source Code created on: 2024-02-18 08:37:46
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* map the pot value in the oled to show the */
/* speedometer as of a car ,on the oled , and toggle */
/* between 3 interfeces of the speedo meter using the */
/* push button */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include //https://github.com/evert-arias/EasyButton
#include
#include
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void displaySpeedometer(int speed);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t button_PushButton_PIN_D2 = 2;
/***** DEFINITION OF ANALOG INPUT PINS *****/
const uint8_t button1_Potentiometer_Vout_PIN_A0 = A0;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
EasyButton button(button_PushButton_PIN_D2);
Adafruit_SSD1306 display(128, 64, &Wire, -1);
int speed = 0;
int prevSpeed = 0;
int interface = 1;
void setup(void)
{
// Put your setup code here, to run once:
Serial.begin(115200);
button.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(2);
display.setCursor(0, 0);
display.println("Speedometer");
display.display();
}
void loop(void)
{
// Put your main code here, to run repeatedly:
button.read();
if (button.wasPressed())
{
interface++;
if (interface > 3)
interface = 1;
display.clearDisplay();
display.setCursor(0, 0);
switch (interface)
{
case 1:
display.println("Interface 1");
break;
case 2:
display.println("Interface 2");
break;
case 3:
display.println("Interface 3");
break;
}
display.display();
delay(500);
}
// Read speed from potentiometer
int potValue = analogRead(button1_Potentiometer_Vout_PIN_A0);
speed = map(potValue, 0, 1023, 0, 200);
// Only update display if speed has changed
if (speed != prevSpeed)
{
displaySpeedometer(speed);
prevSpeed = speed;
}
}
void displaySpeedometer(int speed)
{
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0, 0);
display.print("Speed: ");
display.print(speed);
display.print(" km/h");
display.display();
}