I'm making a vb code that a user would choose a time and write it to arduino and it will store it and set it as its time,
i defined an array that send the time date parameters ,
then another array in arduino read them. but it doesnt work the variable types are wrong
Any Help Please or another possible way to do this
the arduino code
#include <Time.h>
#include <TimeAlarms.h>
int time[6];
if (Serial.available())
{
for (int i=1 ;i< 6; i++){
time[i] = Serial.read();}
setTime(time[2],time[1],0,time[3],time[4],11);} // set time to ?:?:00 ? ? 2011
}
vb2008 code
Dim dime(6) As Integer
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
dime(1) = Format(Now, "mm")
dime(2) = Format(Now, "hh")
dime(3) = Format(Now, "dd")
dime(4) = Format(Now, "MM")
For i = 1 To 4
myport.WriteLine(dime(i))
Next
End Sub
I see you are sending 4 integers and wait to receive 6 ??
First test your Arduino program with the Serial monitor to check if the receiving end works as expected. Be aware that there is a big difference in sending e.g. the character 5 and the integer 5 and the byte 5. An integer is 2 or 4 bytes.
As I do not know what - myport.WriteLine(dime(i)) - puts on the line
And by the way you must test Serial Available for every character. something like :
for (int i=1 ;i< 6; i++) // or must this be 4?
{
while (Serial.available() == 0); // wait until byte arrives
time[i] = Serial.read();
}
setTime(time[2],time[1],0,time[3],time[4],11);}
if (Serial.available())
{
for (int i=1 ;i< 6; i++){
time[i] = Serial.read();}
You check to see there is at least one character available, then go ahead and read 5? (indices go from zero in C)
What if there's only one character available when you call Serial.available?
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim Expr1 = uDate(Now())
TextBox1.Text = "T" & Expr1
End Sub