User manual

044 lcd.print(":");
045 }
046 if(Minute < 60)
047 {
048 if(Minute < 10) lcd.print("0");
049 lcd.print(Minute);
050 lcd.print(":");
051 }
052 if(Second < 60)
053 {
054 if(Second < 10) lcd.print("0");
055 lcd.print(Second);
056 }
057 }
058
059 Serial.flush();
060 delay(100);
061 }
The basic structure of the program corresponds to that of the
regular clock (RTC) that we have already learned about at the
beginning of the learning package.
This time, we receive no data in the VB.NET-program, but send
data from the PC to the Arduino™. The data correspond to hours,
minutes and seconds in the form of bytes. We read them with the
Arduino™ when
Serial.available()
is larger than three. This
characterises that three bytes are pending in the reception
buffer. We use
Serial.read()
to systematically read in the three
arriving bytes and assign them to the Arduino™-variables for
hour, minute and second. That is it on the side of Arduino™.
Let us look at the transmission function in the VB.NET program.
For this, we use a timer set to 500 ms.
001 Private Sub Timer1_Tick(sender As System.Object, e As
System.EventArgs) Handles Timer1.Tick
002
003 If SerialPort1.IsOpen Then
004
005 SerialPort1.Write(Chr(Now.Hour) & Chr(Now.
Minute) & Chr(Now.Second))
006 Label1.Text = Now.Hour & ":" & Now.Minute &
":" & Now.Second
007
008 End If
009 End Sub