Advertisement
pleasedontcode

Button Blink rev_01

Jan 23rd, 2024
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Button Blink
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2024-01-23 13:58:19
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* a potentio to set the time or duration, and a push */
  21.     /* button to start and activate the blinking of led1, */
  22.     /* the duration is displayed on the LCD. */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Arduino.h>
  27. #include <Wire.h>
  28. #include <EasyButton.h>
  29. #include <LiquidCrystal_I2C.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t start_PushButton_PIN_D2 = 2;
  37.  
  38. /***** DEFINITION OF ANALOG INPUT PINS *****/
  39. const uint8_t volume_Potentiometer_Vout_PIN_A0 = A0;
  40.  
  41. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  42. const uint8_t led1_LED_PIN_D3 = 3;
  43.  
  44. /***** DEFINITION OF I2C PINS *****/
  45. const uint8_t lcd_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  46. const uint8_t lcd_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  47. const uint8_t lcd_LCD1602I2C_I2C_SLAVE_ADDRESS = 0x27;
  48.  
  49. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  50. EasyButton startButton(start_PushButton_PIN_D2);
  51. LiquidCrystal_I2C lcd(lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2);
  52.  
  53. void setup(void)
  54. {
  55.   // Start the button
  56.   startButton.begin();
  57.  
  58.   // Initialize the LCD
  59.   lcd.begin(16, 2);
  60.  
  61.   // Set the pin modes
  62.   pinMode(volume_Potentiometer_Vout_PIN_A0, INPUT);
  63.   pinMode(led1_LED_PIN_D3, OUTPUT);
  64. }
  65.  
  66. void loop(void)
  67. {
  68.   // Read the potentiometer value
  69.   int potValue = analogRead(volume_Potentiometer_Vout_PIN_A0);
  70.  
  71.   // Map the potentiometer value to the duration range
  72.   int duration = map(potValue, 0, 1023, 100, 5000);
  73.  
  74.   // Display the duration on the LCD
  75.   lcd.setCursor(0, 0);
  76.   lcd.print("Duration: ");
  77.   lcd.print(duration);
  78.   lcd.print(" ms");
  79.  
  80.   // Check if the button is pressed
  81.   if (startButton.read())
  82.   {
  83.     // Start blinking the LED for the specified duration
  84.     digitalWrite(led1_LED_PIN_D3, HIGH);
  85.     delay(duration);
  86.     digitalWrite(led1_LED_PIN_D3, LOW);
  87.   }
  88. }
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement