/********* 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: GearCarIndicator
- Source Code compiled for: Arduino Uno
- Source Code created on: 2023-09-17 15:52:38
- Source Code generated by: James
********* Pleasedontcode.com **********/
/****** DEFINITION OF LIBRARIES *****/
#include
#include
#include
#include
/****** SYSTEM REQUIREMENT 1 *****/
/* The display shows the indication of the gear from */
/* 1 to 6. At the startup, the system shall show "N" */
/* as Neutral. */
/****** SYSTEM REQUIREMENT 2 *****/
/* If the gear up switch is released, so the gear */
/* value shall be increased by 1. If the gear down */
/* switch is released, so the gear value shall be */
/* decreased by 1. */
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t GearUp_PushButton_PIN_D2 = 2;
const uint8_t GearDown_PushButton_PIN_D3 = 3;
/***** DEFINITION OF I2C PINS *****/
const uint8_t display_SSD1306OledDisplay_I2C_PIN_SDA_A4 = A4;
const uint8_t display_SSD1306OledDisplay_I2C_PIN_SCL_A5 = A5;
const uint8_t display_SSD1306OledDisplay_I2C_SLAVE_ADDRESS = 60;
// Instantiate EasyButton objects for gear up and gear down buttons
EasyButton gearUpButton(GearUp_PushButton_PIN_D2);
EasyButton gearDownButton(GearDown_PushButton_PIN_D3);
// Instantiate SSD1306 display object
Adafruit_SSD1306 display(display_SSD1306OledDisplay_I2C_SLAVE_ADDRESS);
void setup(void)
{
// put your setup code here, to run once:
pinMode(GearUp_PushButton_PIN_D2, INPUT_PULLUP);
pinMode(GearDown_PushButton_PIN_D3, INPUT_PULLUP);
// Initialize the SSD1306 display
display.begin(SSD1306_SWITCHCAPVCC, display_SSD1306OledDisplay_I2C_SLAVE_ADDRESS);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(0, 0);
display.println("N");
display.display();
}
void loop(void)
{
// put your main code here, to run repeatedly:
// Check if the gear up button is released
if (gearUpButton.isReleased())
{
// Increase the gear value by 1
static uint8_t gear = 0;
gear++;
if (gear > 6)
{
gear = 6;
}
// Update the display with the new gear value
display.clearDisplay();
display.setCursor(0, 0);
display.println(gear);
display.display();
}
// Check if the gear down button is released
if (gearDownButton.isReleased())
{
// Decrease the gear value by 1
static uint8_t gear = 0;
if (gear > 0)
{
gear--;
}
// Update the display with the new gear value
display.clearDisplay();
display.setCursor(0, 0);
display.println(gear);
display.display();
}
}