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 Toggle
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-11-03 12:45:53
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* il sistema inizia con il led verde acceso . se */
- /* premo il pulsante 1 non succede nulla. quando */
- /* premo il pulsante due il sistema si sblocca e */
- /* quindi quando premo il pulsante 1 cambia il led */
- /* che si accende. se premo di nuovo il pulsante 2 il */
- /* sistema bloc */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* do not use pullup */
- /****** 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); // Function prototype for updating outputs
- /***** 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 ledrosso_LED_PIN_D4 = 4;
- const uint8_t ledverde_LED_PIN_D5 = 5;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool ledrosso_LED_PIN_D4_rawData = 0; // Red LED state
- bool ledverde_LED_PIN_D5_rawData = 1; // Green LED state (starts ON)
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Initialize EasyButton objects for each button without pull-up resistors
- EasyButton button1(button1_PushButton_PIN_D2, 35, false); // No pullup
- EasyButton button2(button2_PushButton_PIN_D3, 35, false); // No pullup
- // Variable to track if the system is unlocked
- bool systemUnlocked = false;
- // Function to handle button press events
- void onButton1Pressed() {
- if (systemUnlocked) { // Only toggle the red LED if the system is unlocked
- ledrosso_LED_PIN_D4_rawData = !ledrosso_LED_PIN_D4_rawData; // Toggle LED state
- }
- }
- void onButton2Pressed() {
- systemUnlocked = !systemUnlocked; // Toggle system lock state
- // If the system is locked, turn off the red LED
- if (!systemUnlocked) {
- ledrosso_LED_PIN_D4_rawData = 0; // Ensure red LED is off when locked
- }
- }
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(button1_PushButton_PIN_D2, INPUT); // No pull-up resistor
- pinMode(button2_PushButton_PIN_D3, INPUT); // No pull-up resistor
- pinMode(ledrosso_LED_PIN_D4, OUTPUT);
- pinMode(ledverde_LED_PIN_D5, OUTPUT);
- // Initialize the green LED to be ON
- digitalWrite(ledverde_LED_PIN_D5, HIGH);
- // Initialize the EasyButton objects
- button1.begin();
- button2.begin();
- // Attach button press event handlers
- button1.onPressed(onButton1Pressed);
- button2.onPressed(onButton2Pressed);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- button1.read(); // Read the state of button 1
- button2.read(); // Read the state of button 2
- updateOutputs(); // Refresh output data
- }
- void updateOutputs()
- {
- digitalWrite(ledrosso_LED_PIN_D4, ledrosso_LED_PIN_D4_rawData);
- digitalWrite(ledverde_LED_PIN_D5, ledverde_LED_PIN_D5_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement