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 Cycle
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2023-12-09 18:37:21
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* RUN A RGB LED USING 2 BUTTONS the buttons run 3 */
- /* colors green yellow red consecutively button 1 */
- /* changes colors up and button 2 changes colors down */
- /****** 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;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- EasyButton button1(button1_PushButton_PIN_D2);
- EasyButton button2(button2_PushButton_PIN_D3);
- uint8_t currentColor = 0;
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(button1_PushButton_PIN_D2, INPUT_PULLUP);
- pinMode(button2_PushButton_PIN_D3, INPUT_PULLUP);
- pinMode(led_LEDRGB_Red_PIN_D4, OUTPUT);
- pinMode(led_LEDRGB_Green_PIN_D5, OUTPUT);
- pinMode(led_LEDRGB_Blue_PIN_D6, OUTPUT);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- button1.read();
- button2.read();
- // Change color up when button 1 is pressed
- if (button1.isPressed()) {
- currentColor++;
- if (currentColor > 2) {
- currentColor = 0;
- }
- }
- // Change color down when button 2 is pressed
- if (button2.isPressed()) {
- if (currentColor == 0) {
- currentColor = 2;
- } else {
- currentColor--;
- }
- }
- // Display the current color
- switch (currentColor) {
- case 0:
- digitalWrite(led_LEDRGB_Red_PIN_D4, HIGH);
- digitalWrite(led_LEDRGB_Green_PIN_D5, LOW);
- digitalWrite(led_LEDRGB_Blue_PIN_D6, LOW);
- break;
- case 1:
- digitalWrite(led_LEDRGB_Red_PIN_D4, LOW);
- digitalWrite(led_LEDRGB_Green_PIN_D5, HIGH);
- digitalWrite(led_LEDRGB_Blue_PIN_D6, LOW);
- break;
- case 2:
- digitalWrite(led_LEDRGB_Red_PIN_D4, LOW);
- digitalWrite(led_LEDRGB_Green_PIN_D5, LOW);
- digitalWrite(led_LEDRGB_Blue_PIN_D6, HIGH);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement