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: "Digital Input/Output"
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2024-04-07 10:06:03
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* when the easy button was pressed, the green led */
- /* flashed 10 times */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* when the green led stops turn on the red led for */
- /* 15 seconds */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t tilt_PushButton_PIN_D2 = 2;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t red_LED_PIN_D3 = 3;
- const uint8_t green_LED_PIN_D4 = 4;
- const uint8_t bazer_PassiveBuzzer_Signal_PIN_D5 = 5;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool red_LED_PIN_D3_rawData = 0;
- bool green_LED_PIN_D4_rawData = 0;
- bool bazer_PassiveBuzzer_Signal_PIN_D5_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float red_LED_PIN_D3_phyData = 0.0;
- float green_LED_PIN_D4_phyData = 0.0;
- float bazer_PassiveBuzzer_Signal_PIN_D5_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- EasyButton tilt_PushButton(tilt_PushButton_PIN_D2);
- bool isButtonPressed = false;
- int blinkCount = 0;
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(tilt_PushButton_PIN_D2, INPUT_PULLUP);
- pinMode(red_LED_PIN_D3, OUTPUT);
- pinMode(green_LED_PIN_D4, OUTPUT);
- pinMode(bazer_PassiveBuzzer_Signal_PIN_D5, OUTPUT);
- tilt_PushButton.begin();
- tilt_PushButton.onPressed([]() {
- // Button pressed event handler
- Serial.println("Button pressed");
- isButtonPressed = true;
- });
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- tilt_PushButton.read(); // Read button state
- if (isButtonPressed) {
- // Flashes the green LED 10 times
- if (blinkCount < 10) {
- digitalWrite(green_LED_PIN_D4, HIGH);
- delay(500);
- digitalWrite(green_LED_PIN_D4, LOW);
- delay(500);
- blinkCount++;
- } else {
- // Turn on the red LED for 15 seconds
- digitalWrite(green_LED_PIN_D4, LOW);
- digitalWrite(red_LED_PIN_D3, HIGH);
- delay(15000);
- digitalWrite(red_LED_PIN_D3, LOW);
- isButtonPressed = false;
- blinkCount = 0;
- }
- }
- }
- void updateOutputs()
- {
- digitalWrite(red_LED_PIN_D3, red_LED_PIN_D3_rawData);
- digitalWrite(green_LED_PIN_D4, green_LED_PIN_D4_rawData);
- digitalWrite(bazer_PassiveBuzzer_Signal_PIN_D5, bazer_PassiveBuzzer_Signal_PIN_D5_rawData);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement