We control 4 valves with Arduino ethernet and it works well. We see the data (which valve is on and milliseconds that it is on) via arduino software.
We would like to know the exact date and time that valve is on. How could we add timestamp in our data? With Gobetwino for example? Or you suggest something else?
Furthermore, we would like to program Arduino in order to start its program in certain time. For example to start the program at 10:00:00. May I loose some seconds if I start it manually.
try to create your clock.
Thi is my first software. I think that it is better to check if everything is ok. I used this one to display the sec form 0 to 9 in one 7 Seg display.
With pin 3 you can increment minutes and with pin 5 hours.
If you need, you can check the time with the serial port.
If you need, I can create the connection.
// 24h Clock
int BCD[] = {0,13,12,11,10,9,8,7,6};
int digit[] = {0,0,0,0,0,0,0,0,0};
int disp[] = {0,0,0,0};
int P_ORA_SU =5;
int P_MINUTO_SU =3;
int secondo = 1000;
int minuto = 60000;
int ora = 60*60000;
unsigned long mem_sec_u=0;
unsigned long mem_sec_d=0;
unsigned long mem_min_u=0;
unsigned long mem_min_d=0;
unsigned long mem_ora_u=0;
unsigned long mem_ora_d=0;
unsigned long lastDebounceTime=0;
unsigned long debounceDelay=50;
int sec_u=0;
int sec_d=0;
int min_u=0;
int min_d=0;
int ora_u=0;
int ora_d=0;
int inc_min=0;
int inc_ora=0;
int inc_min_mem=0;
int inc_ora_mem=0;
int last_inc_min_state=0;
int last_inc_ora_state=0;
void setup() {
Serial.begin(9600);
pinMode(BCD[1], OUTPUT);
pinMode(BCD[2], OUTPUT);
pinMode(BCD[3], OUTPUT);
pinMode(BCD[4], OUTPUT);
pinMode(BCD[5], OUTPUT);
pinMode(BCD[6], OUTPUT);
pinMode(BCD[7], OUTPUT);
pinMode(P_MINUTO_SU, INPUT);
pinMode(P_ORA_SU, INPUT);
};
void loop (){
inc_min=digitalRead(P_MINUTO_SU);
inc_ora=digitalRead(P_ORA_SU);
// Anti bump per incremento minuti
if (inc_min != last_inc_min_state){
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (inc_min != inc_min_mem) {
inc_min_mem = inc_min;
// only toggle the LED if the new button state is HIGH
if (inc_min == HIGH) {
min_u=min_u++;
}
}
}
//Antibump per incremento ora
if (inc_ora != last_inc_ora_state){
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (inc_ora != inc_ora_mem) {
inc_ora_mem = inc_ora;
// only toggle the LED if the new button state is HIGH
if (inc_ora == HIGH) {
ora_u=ora_u++;
}
}
}
unsigned long currentMillis = millis();
if(currentMillis - mem_sec_u > secondo) {
mem_sec_u=currentMillis;
sec_u=sec_u+1;
if (sec_u>9) {
sec_u=0;
sec_d=sec_d++;
if (sec_d>5) {
sec_d=0;
min_u=min_u++;
}
if (min_u>9) {
min_u=0;
min_d=min_d++;
}
if (min_d>5) {
min_d=0;
ora_u=ora_u++;
}
if (ora_u>9) {
ora_u=0;
ora_d=ora_d++;
}
if ((ora_d==2) && (ora_u>=4)) {
ora_u=0;
ora_d=0;
}
}
if (min_u>9) {
min_u=0;
min_d=min_d++;
}
if (min_d>9) {
min_d=0;
ora_u=ora_u++;
}
if (ora_u>9) {
ora_u=0;
ora_d=ora_d++;
}
if ((ora_d>=2) && (ora_u>4)) {
ora_u=0;
}
if (ora_d>2) {
ora_d=0;
}
Serial.print(ora_d);
Serial.print(ora_u);
Serial.print(":");
Serial.print(min_d);
Serial.print(min_u);
Serial.print(":");
Serial.print(sec_d);
Serial.print(sec_u);
Serial.print("--");
Serial.println(inc_min);
}
switch (sec_u) {
case 0 :
digit[1] = 1;
digit[2] = 1;
digit[3] = 1;
digit[4] = 1;
digit[5] = 1;
digit[6] = 0;
digit[7] = 1;
break;
case 1 :
digit[1] = 0;
digit[2] = 1;
digit[3] = 1;
digit[4] = 0;
digit[5] = 0;
digit[6] = 0;
digit[7] = 0;
break;
case 2 :
digit[1] = 1;
digit[2] = 1;
digit[3] = 0;
digit[4] = 1;
digit[5] = 1;
digit[6] = 1;
digit[7] = 0;
break;
case 3 :
digit[1] = 1;
digit[2] = 1;
digit[3] = 1;
digit[4] = 1;
digit[5] = 0;
digit[6] = 1;
digit[7] = 0;
break;
case 4 :
digit[1] = 0;
digit[2] = 1;
digit[3] = 1;
digit[4] = 0;
digit[5] = 0;
digit[6] = 1;
digit[7] = 1;
break;
case 5 :
digit[1] = 1;
digit[2] = 0;
digit[3] = 1;
digit[4] = 1;
digit[5] = 0;
digit[6] = 1;
digit[7] = 1;
break;
case 6 :
digit[1] = 1;
digit[2] = 0;
digit[3] = 1;
digit[4] = 1;
digit[5] = 1;
digit[6] = 1;
digit[7] = 1;
break;
case 7 :
digit[1] = 1;
digit[2] = 1;
digit[3] = 1;
digit[4] = 0;
digit[5] = 0;
digit[6] = 0;
digit[7] = 0;
break;
case 8 :
digit[1] = 1;
digit[2] = 1;
digit[3] = 1;
digit[4] = 1;
digit[5] = 1;
digit[6] = 1;
digit[7] = 1;
break;
case 9 :
digit[1] = 1;
digit[2] = 1;
digit[3] = 1;
digit[4] = 1;
digit[5] = 0;
digit[6] = 1;
digit[7] = 1;
break;
}
//Scrive nel primo display a destra
for (int i=1; i <= 7; i++){
digitalWrite(BCD[i], digit[i]);
}
}