Hello,
I want to send some data with a checksum at the end.
I always used the switch case to get my data over to an other device. before I did send a number and a letter that tells me what it is used for (for example "1245a")
I always get the same problem...
I send something but I wound be displayed until I send something after that and that will be only displayed when I send something after that and so on...
Arduino >>>>>>>>>>>>>> Processing
100b >>>>>>>>>>>>>>>>
100b111c >>>>>>>>>>>> 100b
100b111c7>>>>>>>>>>>> 100b111c and so on...
until now I did send the last value double so that it gets send but that is not a good way.
I get the same problem with the "new checksum way" so it must have something to do with the switch case ?
I hope someone understands me and can help me ^^
here is a little sketch I did on a Arduino Mega and Processing:
Arduino:
const int Size = 40;
int Array[Size];
int Data[Size];
unsigned long check =4;
unsigned long confirmed = 0;
void setup() {
Serial.begin(57600); // put your setup code here, to run once:
Serial3.begin(57600); // put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
serial();
// for(int i = 0; i < Size; i++){
// Serial.print(Data[i]);
// Serial.print(",");
// }
Serial.print(confirmed);
Serial.println(" End");
delay(3);
}
void serial(){
static int v = 0;
static int i = 0;
if ( Serial3.available() >= 2) { /// achtung serial "3" !!!!
char ch = Serial3.read();/// achtung serial "3" !!!!
if ( ch >= '0' && ch <= '9') {
v = v *10 + ch - '0';
}
else
{
switch(ch)
{
//----------------|right side|-----------------------------------
case ',':
Array[i] = v;
check += v;
i++;
break;
case '
Processing:
import processing.serial.*;
int o = 0;
Serial port;
void setup(){
println(Serial.list());
port = new Serial(this, Serial.list()[0], 57600);
}
void draw(){
port.write(o+","+1+","+1+","+1+","+1+","+1+","+1+","+1+","+(7+o)+"$");
println(o+","+1+","+1+","+1+","+1+","+1+","+1+","+1+","+(7+o)+"$");
o++;
delay(150);
}
:if(check == v){
for(int j = 0; j < Size; j++){
Data[j] = Array[j];
}
}
i = 0;
confirmed = check;
check = 0;
break;
}
v=0;
}
}
}
Processing:
§DISCOURSE_HOISTED_CODE_1§
