Advertisement
pleasedontcode

Button Sequence rev_03

Dec 9th, 2023
80
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 Sequence
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-09 19:13:23
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* run a rgb led with 2 buttons the buttons run 3 */
  21.     /* colors green yellow red respectively button one */
  22.     /* goes up the colors and stops at red button 2 goes */
  23.     /* down the colors and stops at green */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <Arduino.h>
  28. #include <EasyButton.h>
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup();
  32. void loop();
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t button1_PushButton_PIN_D2 = 2;
  36. const uint8_t button2_PushButton_PIN_D3 = 3;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t led_LEDRGB_Red_PIN_D4 = 4;
  40. const uint8_t led_LEDRGB_Green_PIN_D5 = 5;
  41. const uint8_t led_LEDRGB_Blue_PIN_D6 = 6;
  42.  
  43. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  44. EasyButton button1(button1_PushButton_PIN_D2);
  45. EasyButton button2(button2_PushButton_PIN_D3);
  46.  
  47. bool led1On = false;
  48. bool led2On = false;
  49. bool led3On = false;
  50.  
  51. void setup() {
  52.     // Set the button pins as input with pull-up resistors enabled
  53.     pinMode(button1_PushButton_PIN_D2, INPUT_PULLUP);
  54.     pinMode(button2_PushButton_PIN_D3, INPUT_PULLUP);
  55.  
  56.     // Set the LED pins as output
  57.     pinMode(led_LEDRGB_Red_PIN_D4, OUTPUT);
  58.     pinMode(led_LEDRGB_Green_PIN_D5, OUTPUT);
  59.     pinMode(led_LEDRGB_Blue_PIN_D6, OUTPUT);
  60. }
  61.  
  62. void loop() {
  63.     // Read the button states
  64.     button1.read();
  65.     button2.read();
  66.  
  67.     // Check if button 1 is pressed
  68.     if (button1.isPressed()) {
  69.         if (!led3On) {
  70.             digitalWrite(led_LEDRGB_Blue_PIN_D6, HIGH);
  71.             led3On = true;
  72.         } else if (!led2On) {
  73.             digitalWrite(led_LEDRGB_Green_PIN_D5, HIGH);
  74.             led2On = true;
  75.         } else if (!led1On) {
  76.             digitalWrite(led_LEDRGB_Red_PIN_D4, HIGH);
  77.             led1On = true;
  78.         }
  79.     }
  80.  
  81.     // Check if button 2 is pressed
  82.     if (button2.isPressed()) {
  83.         if (led1On) {
  84.             digitalWrite(led_LEDRGB_Red_PIN_D4, LOW);
  85.             led1On = false;
  86.         } else if (led2On) {
  87.             digitalWrite(led_LEDRGB_Green_PIN_D5, LOW);
  88.             led2On = false;
  89.         } else if (led3On) {
  90.             digitalWrite(led_LEDRGB_Blue_PIN_D6, LOW);
  91.             led3On = false;
  92.         }
  93.     }
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement