This program will send the time of when a power shortage is available and counts the number
hrs/mins/secs and send the data.
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
const int deviceOne = 3;
const int deviceTwo = 4;
const int deviceThree = 5;
const int ledOut = 13;
int stateOne = 0;
int stateTwo = 0;
int stateThree = 0 ;
int msgFlag = 0;
int second = 0;
int minute = 0;
int hours = 0;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(deviceOne, INPUT);
pinMode(deviceTwo, INPUT);
pinMode(deviceThree, OUTPUT);
pinMode(ledOut, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
stateOne = digitalRead(deviceOne);
stateTwo = digitalRead(deviceTwo);
stateThree = digitalRead(deviceThree);
if(stateOne==LOW)
{
//send message OFF
msgFlag = 1;
}
while(stateOne == LOW)
{
//start count;
while(second <60)
{
second++;
delay(1000);
if(second == 60)
{
minute++;
second = 0;
}
if(minute == 60)
{
hours++;
minute = 0;
}
}
}
if(stateTwo == LOW)
{ //send message OFF
while(second <60)
{
second++;
delay(1000);
if(second == 60)
{
minute++;
second = 0;
}
if(minute == 60)
{
hours++;
minute = 0;
}
}
}
if(stateThree == LOW)
{
//send message OFF
while(second <60)
{
second++;
delay(1000);
if(second == 60)
{
minute++;
second = 0;
}
if(minute == 60)
{
hours++;
minute = 0;
}
}
}
};
if ((stateOne == HIGH) & (msgFlag == 1))
{
//send message ON
msgFlag = 0;
//get time value
}
}
Moderator edit: code tags