/********* 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 Toggle
- Source Code compiled for: Arduino Uno
- Source Code created on: 2024-04-08 18:29:26
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* I have a push button to digital pin 4 and a led on */
/* pin 8. Pin 8 high turns on the light. When the */
/* button is pressed once I want to turn light on. */
/* Holding the button will start running it and let */
/* it run as long as pr */
/****** SYSTEM REQUIREMENT 2 *****/
/* Button press: 1x on 2x on for 30 sec 3x on for */
/* 30, pause 10, on for 30 If on 1 press turns off */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include //https://github.com/evert-arias/EasyButton
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void onSequenceMatched(void);
void updateOutputs(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t startButton_PushButton_PIN_D4 = 4;
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t ledLight_LED_PIN_D8 = 8;
/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool ledLight_LED_PIN_D8_rawData = 0;
/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float ledLight_LED_PIN_D8_phyData = 0.0;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
EasyButton startButton(startButton_PushButton_PIN_D4); // Provide the pin argument in the constructor
void setup(void)
{
// put your setup code here, to run once:
pinMode(ledLight_LED_PIN_D8, OUTPUT);
startButton.onSequence(3, 30000, onSequenceMatched); // 3 sequences, each lasting for 30 seconds
startButton.begin(); // Call the begin() function without any arguments
}
void loop(void)
{
// put your main code here, to run repeatedly:
startButton.read();
updateOutputs(); // Refresh output data
}
void onSequenceMatched(void)
{
// Button pressed
ledLight_LED_PIN_D8_rawData = !ledLight_LED_PIN_D8_rawData;
}
void updateOutputs(void)
{
digitalWrite(ledLight_LED_PIN_D8, ledLight_LED_PIN_D8_rawData);
}