Hello,
I am trying to create a little software that write the time that the button was turned on or off.
Example: Every time that someone turns on the switch, the Arduino storage this information and when turns off, the Arduino storage this information again. I am very new in this part of the Arduino, so any help is good. Thanks
i already wrote:
(this first one is just to appear the time when i turned on or off the switch.)
#include <EEPROM.h>
#include <Time.h>
//#include <TimeAlarms.h>
const int buttonPin = 3;
int buttonState = 1;
int coco = 0;
int ledPin = 8;
int memoria = 0;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
setTime(8,29,0,24,8,2015); // set time
}
void loop(){
ClockDisplay();
}
void ClockDisplay()
{
buttonState = digitalRead(buttonPin);
//all this are just to, when i turn on the switch the time appears on the //monitor seria
if(buttonState != coco){
coco = 1 - coco;
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
PrintDigits(month());
PrintDigits(year());
Serial.println();
}
}
void printDigits(int digits)
{
Serial.print(":");
if(digits < 10)
Serial.print(‘0’);
Serial.print(digits);
}
void PrintDigits(int digits)
{
Serial.print("/");
if(digits < 10)
Serial.print(‘0’);
Serial.print(digits);
}
(This second one is the one that i am trying to save on the EEPROM).
#include <EEPROM.h>
#include <Time.h>
//#include <TimeAlarms.h>
const int buttonPin = 3;
int buttonState = 1;
int coco = 0;
int ledPin = 8;
int memoria = 0;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
setTime(8,29,0,24,8,2015);
}
void loop(){
ClockDisplay();
}
void ClockDisplay()
{
buttonState = digitalRead(buttonPin);
if(buttonState != coco){
coco = 1 - coco;
EEPROM.write(memoria, second());
memoria = memoria + 1;
}
}
void printDigits(int digits)
{
Serial.print(":");
if(digits < 10)
Serial.print(‘0’);
Serial.print(digits);
}
void PrintDigits(int digits)
{
Serial.print("/");
if(digits < 10)
Serial.print(‘0’);
Serial.print(digits);
}