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 Sequencer
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2023-12-09 19:21:49
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* rgb led with 2 buttons button 1 goes from off to */
- /* green to yellow to red then stops button 2 runs */
- /* from red to yellow to green to off and stops */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- #include <EasyButton.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** 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;
- // Button states
- enum ButtonState {
- OFF,
- GREEN,
- YELLOW,
- RED
- };
- /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
- EasyButton button1(button1_PushButton_PIN_D2);
- EasyButton button2(button2_PushButton_PIN_D3);
- ButtonState button1State = OFF;
- ButtonState button2State = RED;
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(led_LEDRGB_Red_PIN_D4, OUTPUT);
- pinMode(led_LEDRGB_Green_PIN_D5, OUTPUT);
- pinMode(led_LEDRGB_Blue_PIN_D6, OUTPUT);
- button1.begin();
- button2.begin();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- button1.read();
- button2.read();
- // Button 1 sequence
- if (button1.wasPressed()) {
- switch (button1State) {
- case OFF:
- digitalWrite(led_LEDRGB_Green_PIN_D5, HIGH);
- digitalWrite(led_LEDRGB_Blue_PIN_D6, LOW);
- digitalWrite(led_LEDRGB_Red_PIN_D4, LOW);
- button1State = GREEN;
- break;
- case GREEN:
- digitalWrite(led_LEDRGB_Green_PIN_D5, LOW);
- digitalWrite(led_LEDRGB_Blue_PIN_D6, HIGH);
- digitalWrite(led_LEDRGB_Red_PIN_D4, LOW);
- button1State = YELLOW;
- break;
- case YELLOW:
- digitalWrite(led_LEDRGB_Green_PIN_D5, LOW);
- digitalWrite(led_LEDRGB_Blue_PIN_D6, LOW);
- digitalWrite(led_LEDRGB_Red_PIN_D4, HIGH);
- button1State = RED;
- break;
- case RED:
- digitalWrite(led_LEDRGB_Green_PIN_D5, LOW);
- digitalWrite(led_LEDRGB_Blue_PIN_D6, LOW);
- digitalWrite(led_LEDRGB_Red_PIN_D4, LOW);
- button1State = OFF;
- break;
- }
- }
- // Button 2 sequence
- if (button2.wasPressed()) {
- switch (button2State) {
- case RED:
- digitalWrite(led_LEDRGB_Green_PIN_D5, LOW);
- digitalWrite(led_LEDRGB_Blue_PIN_D6, LOW);
- digitalWrite(led_LEDRGB_Red_PIN_D4, HIGH);
- button2State = YELLOW;
- break;
- case YELLOW:
- digitalWrite(led_LEDRGB_Green_PIN_D5, LOW);
- digitalWrite(led_LEDRGB_Blue_PIN_D6, HIGH);
- digitalWrite(led_LEDRGB_Red_PIN_D4, LOW);
- button2State = GREEN;
- break;
- case GREEN:
- digitalWrite(led_LEDRGB_Green_PIN_D5, HIGH);
- digitalWrite(led_LEDRGB_Blue_PIN_D6, LOW);
- digitalWrite(led_LEDRGB_Red_PIN_D4, LOW);
- button2State = OFF;
- break;
- case OFF:
- digitalWrite(led_LEDRGB_Green_PIN_D5, LOW);
- digitalWrite(led_LEDRGB_Blue_PIN_D6, LOW);
- digitalWrite(led_LEDRGB_Red_PIN_D4, LOW);
- button2State = RED;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement