/********* 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: "Interval Activations"
- Source Code NOT compiled for: Arduino Uno
- Source Code created on: 2024-06-07 13:36:55
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* initiate the system to control led, buzzer and */
/* solenoid each going on in every 5, 10, and 20 */
/* minutes respectively for 3seconds */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include // Include TimerOne library for handling timing intervals
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);
void timerISR(void);
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t LED_PIN = 2;
const uint8_t BUZZER_PIN = 3;
const uint8_t SOLENOID_PIN = 4;
/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool LED_PIN_rawData = 0;
bool BUZZER_PIN_rawData = 0;
bool SOLENOID_PIN_rawData = 0;
/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float LED_PIN_phyData = 0.0;
float BUZZER_PIN_phyData = 0.0;
float SOLENOID_PIN_phyData = 0.0;
/***** DEFINITION OF TIMING VARIABLES *****/
unsigned long lastLEDTime = 0;
unsigned long lastBuzzerTime = 0;
unsigned long lastSolenoidTime = 0;
const unsigned long LED_INTERVAL = 5 * 60 * 1000; // 5 minutes in milliseconds
const unsigned long BUZZER_INTERVAL = 10 * 60 * 1000; // 10 minutes in milliseconds
const unsigned long SOLENOID_INTERVAL = 20 * 60 * 1000; // 20 minutes in milliseconds
const unsigned long ON_DURATION = 3000; // 3 seconds in milliseconds
void setup(void)
{
// put your setup code here, to run once:
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(SOLENOID_PIN, OUTPUT);
// Initialize Timer1 to call timerISR every 1 second
Timer1.initialize(1000000); // 1 second in microseconds
Timer1.attachInterrupt(timerISR);
}
void loop(void)
{
// put your main code here, to run repeatedly:
updateOutputs(); // Refresh output data
}
void updateOutputs()
{
unsigned long currentTime = millis();
// Check if it's time to turn on the LED
if (currentTime - lastLEDTime >= LED_INTERVAL)
{
LED_PIN_rawData = 1; // Turn on LED
lastLEDTime = currentTime; // Reset the timer
}
// Check if it's time to turn off the LED
if (LED_PIN_rawData && (currentTime - lastLEDTime >= ON_DURATION))
{
LED_PIN_rawData = 0; // Turn off LED
}
// Check if it's time to turn on the Buzzer
if (currentTime - lastBuzzerTime >= BUZZER_INTERVAL)
{
BUZZER_PIN_rawData = 1; // Turn on Buzzer
lastBuzzerTime = currentTime; // Reset the timer
}
// Check if it's time to turn off the Buzzer
if (BUZZER_PIN_rawData && (currentTime - lastBuzzerTime >= ON_DURATION))
{
BUZZER_PIN_rawData = 0; // Turn off Buzzer
}
// Check if it's time to turn on the Solenoid
if (currentTime - lastSolenoidTime >= SOLENOID_INTERVAL)
{
SOLENOID_PIN_rawData = 1; // Turn on Solenoid
lastSolenoidTime = currentTime; // Reset the timer
}
// Check if it's time to turn off the Solenoid
if (SOLENOID_PIN_rawData && (currentTime - lastSolenoidTime >= ON_DURATION))
{
SOLENOID_PIN_rawData = 0; // Turn off Solenoid
}
// Update the physical outputs
digitalWrite(LED_PIN, LED_PIN_rawData);
digitalWrite(BUZZER_PIN, BUZZER_PIN_rawData);
digitalWrite(SOLENOID_PIN, SOLENOID_PIN_rawData);
}
void timerISR()
{
// This function is called every 1 second by Timer1
// We can use it to handle any periodic tasks if needed
}
/* END CODE */