Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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 Sequence
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2023-12-09 19:13:23
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* run a rgb led with 2 buttons the buttons run 3 */
- /* colors green yellow red respectively button one */
- /* goes up the colors and stops at red button 2 goes */
- /* down the colors and stops at green */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- #include <EasyButton.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup();
- void loop();
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t button1_PushButton_PIN_D2 = 2;
- const uint8_t button2_PushButton_PIN_D3 = 3;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t led_LEDRGB_Red_PIN_D4 = 4;
- const uint8_t led_LEDRGB_Green_PIN_D5 = 5;
- const uint8_t led_LEDRGB_Blue_PIN_D6 = 6;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- EasyButton button1(button1_PushButton_PIN_D2);
- EasyButton button2(button2_PushButton_PIN_D3);
- bool led1On = false;
- bool led2On = false;
- bool led3On = false;
- void setup() {
- // Set the button pins as input with pull-up resistors enabled
- pinMode(button1_PushButton_PIN_D2, INPUT_PULLUP);
- pinMode(button2_PushButton_PIN_D3, INPUT_PULLUP);
- // Set the LED pins as output
- pinMode(led_LEDRGB_Red_PIN_D4, OUTPUT);
- pinMode(led_LEDRGB_Green_PIN_D5, OUTPUT);
- pinMode(led_LEDRGB_Blue_PIN_D6, OUTPUT);
- }
- void loop() {
- // Read the button states
- button1.read();
- button2.read();
- // Check if button 1 is pressed
- if (button1.isPressed()) {
- if (!led3On) {
- digitalWrite(led_LEDRGB_Blue_PIN_D6, HIGH);
- led3On = true;
- } else if (!led2On) {
- digitalWrite(led_LEDRGB_Green_PIN_D5, HIGH);
- led2On = true;
- } else if (!led1On) {
- digitalWrite(led_LEDRGB_Red_PIN_D4, HIGH);
- led1On = true;
- }
- }
- // Check if button 2 is pressed
- if (button2.isPressed()) {
- if (led1On) {
- digitalWrite(led_LEDRGB_Red_PIN_D4, LOW);
- led1On = false;
- } else if (led2On) {
- digitalWrite(led_LEDRGB_Green_PIN_D5, LOW);
- led2On = false;
- } else if (led3On) {
- digitalWrite(led_LEDRGB_Blue_PIN_D6, LOW);
- led3On = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement