/********* 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: Fuel Monitor
- Source Code NOT compiled for: Arduino Uno
- Source Code created on: 2024-08-17 22:01:06
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* The application shall read fuel levels via a */
/* potentiometer, displaying results on an I2C */
/* LiquidCrystal display, and trigger an LED and */
/* buzzer when fuel is critically low, enhancing user */
/* interaction and safety. */
/****** SYSTEM REQUIREMENT 2 *****/
/* a menu for lcd to adjust buzzer and led settings */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include
#include //https://github.com/evert-arias/EasyButton
#include //https://github.com/marcoschwartz/LiquidCrystal_I2C
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);
void displayFuelLevel(float fuelLevel);
void checkFuelLevel(float fuelLevel);
void menu(); // Function to handle the menu for adjusting settings
/***** DEFINITION OF ANALOG INPUT PINS *****/
const uint8_t fuelLevel_Potentiometer_Vout_PIN_A0 = A0;
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t led_LED_PIN_D3 = 3;
const uint8_t buzzer_ActiveBuzzer_output_PIN_D4 = 4;
/***** DEFINITION OF I2C PINS *****/
const uint8_t lcd_LCD1602I2C_I2C_SLAVE_ADDRESS = 0x27; // Updated I2C address to common value for LCD
/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
bool led_LED_PIN_D3_rawData = 0;
bool buzzer_ActiveBuzzer_output_PIN_D4_rawData = 0;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
// Create an instance of the EasyButton class for button handling
#define BUTTON_PIN 2 // Define the button pin
EasyButton button(BUTTON_PIN); // Initialize EasyButton with the button pin
// Create an instance of the LiquidCrystal_I2C class for LCD handling
LiquidCrystal_I2C lcd(lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, 20, 4); // Initialize LCD with I2C address and dimensions
void setup(void)
{
// put your setup code here, to run once:
pinMode(fuelLevel_Potentiometer_Vout_PIN_A0, INPUT);
pinMode(led_LED_PIN_D3, OUTPUT);
pinMode(buzzer_ActiveBuzzer_output_PIN_D4, OUTPUT);
// Initialize the LCD
lcd.init();
lcd.backlight(); // Turn on the backlight for the LCD
// Initialize the button
button.begin(); // Call begin to initialize the button
}
void loop(void)
{
// put your main code here, to run repeatedly:
updateOutputs(); // Refresh output data
// Continuously read the status of the button
button.read(); // Read the button state
// Read fuel level from the potentiometer
float fuelLevel = analogRead(fuelLevel_Potentiometer_Vout_PIN_A0) * (100.0 / 1023.0); // Convert to percentage
// Display the fuel level on the LCD
displayFuelLevel(fuelLevel);
// Check the fuel level and update LED and buzzer
checkFuelLevel(fuelLevel);
// Check if the button is pressed to open the menu
if (button.read()) {
menu(); // Open the menu for adjusting settings
}
}
void updateOutputs()
{
digitalWrite(led_LED_PIN_D3, led_LED_PIN_D3_rawData);
digitalWrite(buzzer_ActiveBuzzer_output_PIN_D4, buzzer_ActiveBuzzer_output_PIN_D4_rawData);
}
void displayFuelLevel(float fuelLevel) {
lcd.setCursor(0, 0);
lcd.print("Fuel Level: ");
lcd.print(fuelLevel);
lcd.print(" %");
}
void checkFuelLevel(float fuelLevel) {
if (fuelLevel < 15.0) { // Critical level threshold
led_LED_PIN_D3_rawData = HIGH; // Turn on LED
buzzer_ActiveBuzzer_output_PIN_D4_rawData = HIGH; // Turn on Buzzer
} else {
led_LED_PIN_D3_rawData = LOW; // Turn off LED
buzzer_ActiveBuzzer_output_PIN_D4_rawData = LOW; // Turn off Buzzer
}
}
void menu() {
// Simple menu implementation to adjust buzzer and LED settings
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Menu:");
lcd.setCursor(0, 1);
lcd.print("1: Buzzer ON/OFF");
lcd.setCursor(0, 2);
lcd.print("2: LED ON/OFF");
lcd.setCursor(0, 3);
lcd.print("Press button to select");
// Wait for button press to select an option
while (!button.read()) {
// Do nothing, just wait
}
// Implement the logic to toggle buzzer and LED settings
// This is a placeholder for the actual implementation
// You can add more detailed logic here based on user input
}
/* END CODE */