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 NOT compiled for: Arduino Uno
- - Source Code created on: 2025-02-28 21:07:34
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* lo start accende led per 5s (timer1 in interrupt) */
- /* dopo si spegne fino alla successiva pressione il */
- /* pulsante di stop (interrupt) spegne l'uscita in */
- /* qualsiasi situazione in interrupt come counter, */
- /* quando arriva a 10 spegnere tutto fino a che non */
- /* si */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t start_PushButton_PIN_D2 = 2;
- const uint8_t stop_PushButton_PIN_D3 = 3;
- const uint8_t count_PushButton_PIN_D4 = 4;
- const uint8_t up_PIN_D8 = 8; // Added for up button
- const uint8_t down_PIN_A4 = A4; // Added for down button
- const uint8_t reset_PIN_D4 = 4; // Reset pin (already defined)
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t out_LED_PIN_D5 = 5;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool out_LED_PIN_D5_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float out_LED_PIN_D5_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Global variables for USER CODE
- int cont = 0;
- int flag = 0;
- bool ledActive = false; // To track if the LED is active
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(start_PushButton_PIN_D2, INPUT_PULLUP);
- pinMode(stop_PushButton_PIN_D3, INPUT_PULLUP);
- pinMode(count_PushButton_PIN_D4, INPUT_PULLUP);
- pinMode(out_LED_PIN_D5, OUTPUT);
- // USER CODE setup
- pinMode(LED_BUILTIN, OUTPUT);
- pinMode(up_PIN_D8, INPUT); // up
- pinMode(down_PIN_A4, INPUT); // down
- pinMode(reset_PIN_D4, INPUT); // reset
- Serial.begin(9600);
- TCCR1A = 0B00000000; // Normal Mode
- TIMSK1 = 0B00000001; // INT on overflow
- TCNT1 = -15625;
- sei();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- // USER CODE loop
- if (flag == 1) { // 5 seconds have passed
- flag = 0;
- ledActive = false; // Deactivate LED
- out_LED_PIN_D5_rawData = LOW; // Turn off LED
- Serial.println("LED turned off after 5 seconds");
- }
- }
- // Function to start the LED
- void startLED() {
- ledActive = true; // Set LED active
- out_LED_PIN_D5_rawData = HIGH; // Turn on LED
- cont = 0; // Reset counter
- Serial.println("LED started");
- }
- // Function to stop the LED
- void stopLED() {
- ledActive = false; // Set LED inactive
- out_LED_PIN_D5_rawData = LOW; // Turn off LED
- cont = 0; // Reset counter
- Serial.println("LED stopped");
- }
- /***** TIMER INTERRUPT FUNCTION *****/
- ISR(TIMER1_OVF_vect) { // Timer interrupt function
- if (ledActive) {
- cont++;
- if (cont >= 5) { // 5 seconds
- flag = 1; // Set flag to indicate timeout
- }
- }
- TCNT1 = -15625; // Reset timer
- }
- // Update outputs
- void updateOutputs()
- {
- digitalWrite(out_LED_PIN_D5, out_LED_PIN_D5_rawData);
- }
- // Button press handling
- void handleButtonPress() {
- if (digitalRead(start_PushButton_PIN_D2) == LOW) {
- startLED(); // Start LED on button press
- }
- if (digitalRead(stop_PushButton_PIN_D3) == LOW) {
- stopLED(); // Stop LED on button press
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement