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: "LED Control"
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2024-06-11 16:08:42
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* This code will 5 leds. The one entered in the app */
- /* will light up when the time comes, until the */
- /* person turns off the alarm */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <SoftwareSerial.h>
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- void onAlarmButtonPressed(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t alarmButton_PushButton_PIN_D5 = 5;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t LEDRGB_Red_PIN_D2 = 2;
- const uint8_t LEDRGB_Green_PIN_D3 = 3;
- const uint8_t LEDRGB_Blue_PIN_D4 = 4;
- const uint8_t LED1_PIN_D6 = 6;
- const uint8_t LED2_PIN_D7 = 7;
- const uint8_t LED3_PIN_D8 = 8;
- const uint8_t LED4_PIN_D9 = 9;
- const uint8_t LED5_PIN_D10 = 10;
- /***** DEFINITION OF Software Serial *****/
- const uint8_t HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
- const uint8_t HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
- SoftwareSerial HC05_mySerial(HC05_mySerial_PIN_SERIAL_RX_A1, HC05_mySerial_PIN_SERIAL_TX_A0);
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool LEDRGB_Red_PIN_D2_rawData = 0;
- bool LEDRGB_Green_PIN_D3_rawData = 0;
- bool LEDRGB_Blue_PIN_D4_rawData = 0;
- bool LED1_PIN_D6_rawData = 0;
- bool LED2_PIN_D7_rawData = 0;
- bool LED3_PIN_D8_rawData = 0;
- bool LED4_PIN_D9_rawData = 0;
- bool LED5_PIN_D10_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float LEDRGB_Red_PIN_D2_phyData = 0.0;
- float LEDRGB_Green_PIN_D3_phyData = 0.0;
- float LEDRGB_Blue_PIN_D4_phyData = 0.0;
- float LED1_PIN_D6_phyData = 0.0;
- float LED2_PIN_D7_phyData = 0.0;
- float LED3_PIN_D8_phyData = 0.0;
- float LED4_PIN_D9_phyData = 0.0;
- float LED5_PIN_D10_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- EasyButton alarmButton(alarmButton_PushButton_PIN_D5);
- void setup(void) {
- // put your setup code here, to run once:
- Serial.begin(115200);
- Serial.println();
- Serial.println(">>> EasyButton example with alarm button <<<");
- pinMode(LEDRGB_Red_PIN_D2, OUTPUT);
- pinMode(LEDRGB_Green_PIN_D3, OUTPUT);
- pinMode(LEDRGB_Blue_PIN_D4, OUTPUT);
- pinMode(LED1_PIN_D6, OUTPUT);
- pinMode(LED2_PIN_D7, OUTPUT);
- pinMode(LED3_PIN_D8, OUTPUT);
- pinMode(LED4_PIN_D9, OUTPUT);
- pinMode(LED5_PIN_D10, OUTPUT);
- HC05_mySerial.begin(9600);
- // Initialize the button
- alarmButton.begin();
- alarmButton.onPressed(onAlarmButtonPressed);
- }
- void loop(void) {
- // put your main code here, to run repeatedly:
- alarmButton.read(); // Read the button state
- updateOutputs(); // Refresh output data
- }
- void updateOutputs() {
- digitalWrite(LEDRGB_Red_PIN_D2, LEDRGB_Red_PIN_D2_rawData);
- digitalWrite(LEDRGB_Green_PIN_D3, LEDRGB_Green_PIN_D3_rawData);
- digitalWrite(LEDRGB_Blue_PIN_D4, LEDRGB_Blue_PIN_D4_rawData);
- digitalWrite(LED1_PIN_D6, LED1_PIN_D6_rawData);
- digitalWrite(LED2_PIN_D7, LED2_PIN_D7_rawData);
- digitalWrite(LED3_PIN_D8, LED3_PIN_D8_rawData);
- digitalWrite(LED4_PIN_D9, LED4_PIN_D9_rawData);
- digitalWrite(LED5_PIN_D10, LED5_PIN_D10_rawData);
- }
- void onAlarmButtonPressed() {
- Serial.println("Alarm button pressed");
- // Add additional actions to be performed when the alarm button is pressed
- // For example, turn off all LEDs
- LEDRGB_Red_PIN_D2_rawData = 0;
- LEDRGB_Green_PIN_D3_rawData = 0;
- LEDRGB_Blue_PIN_D4_rawData = 0;
- LED1_PIN_D6_rawData = 0;
- LED2_PIN_D7_rawData = 0;
- LED3_PIN_D8_rawData = 0;
- LED4_PIN_D9_rawData = 0;
- LED5_PIN_D10_rawData = 0;
- updateOutputs();
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement