CCCPaste

Button Blink rev_01

/********* 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: Button Blink
	- Source Code compiled for: Arduino Nano
	- Source Code created on: 2024-01-23 13:58:19

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* a potentio to set the time or duration, and a push */
	/* button to start and activate the blinking of led1, */
	/* the duration is displayed on the LCD. */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 
#include 
#include 
#include 

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t start_PushButton_PIN_D2 = 2;

/***** DEFINITION OF ANALOG INPUT PINS *****/
const uint8_t volume_Potentiometer_Vout_PIN_A0 = A0;

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t led1_LED_PIN_D3 = 3;

/***** DEFINITION OF I2C PINS *****/
const uint8_t lcd_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
const uint8_t lcd_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
const uint8_t lcd_LCD1602I2C_I2C_SLAVE_ADDRESS = 0x27;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
EasyButton startButton(start_PushButton_PIN_D2);
LiquidCrystal_I2C lcd(lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2);

void setup(void)
{
  // Start the button
  startButton.begin();

  // Initialize the LCD
  lcd.begin(16, 2);

  // Set the pin modes
  pinMode(volume_Potentiometer_Vout_PIN_A0, INPUT);
  pinMode(led1_LED_PIN_D3, OUTPUT);
}

void loop(void)
{
  // Read the potentiometer value
  int potValue = analogRead(volume_Potentiometer_Vout_PIN_A0);

  // Map the potentiometer value to the duration range
  int duration = map(potValue, 0, 1023, 100, 5000);

  // Display the duration on the LCD
  lcd.setCursor(0, 0);
  lcd.print("Duration: ");
  lcd.print(duration);
  lcd.print(" ms");

  // Check if the button is pressed
  if (startButton.read())
  {
    // Start blinking the LED for the specified duration
    digitalWrite(led1_LED_PIN_D3, HIGH);
    delay(duration);
    digitalWrite(led1_LED_PIN_D3, LOW);
  }
}