well, I am getting or something similar...also will get greek letters if I change to read or available:
<
<
2
7
2
>
<
27
>
Using this code, without availabable and read commented, I get available '0' and read is '-1'.
int potPin = 0; // select input pin
int val; // variable to store the value
int lastVal = 0;
void setup() {
Serial.begin(9600);
}
void loop()
{
val = analogRead(potPin); // read the value from the pot
if(abs(val - lastVal) > 5)
{
Serial.println("<");
Serial.println(val);
Serial.println(">");
lastVal=val;
}
}
receiver
//read in value from first arduino of slide pot
//#include "RoboClaw.h"
//#include "BMSerial.h"
//read till end of packet
char string[4]; //can be 4, 8 is fine
int var;
int index = 0;
boolean started=false;
boolean ended=false;
void setup()
{
Serial.begin(9600);
//int v=Serial.available();
//Serial.println(v);
//var=Serial.read();
//Serial.println(var);
}
void loop()
{
while(Serial.available() > 0)
{
var=Serial.read();
if(var=='<')
{
started = true;
index=0;
string[index]='\0';
}
else if(var=='>')
{
ended = true;
break; //break out of while loop when '>' received
}
else if(started)
{
string[index]=var;
index++;
string[index]='\0';
string[index]=var; //store character
}
//x = Serial.read(); //read another string
}
if(started && ended)
{
//convert portion of string to integer representation
int val=atoi(string);
Serial.println("<");
Serial.println(val);
Serial.println(">");
//next time
started = false;
ended = false;
index = 0;
string[index]='\0';
}
}
Testing the sender code and I seems to be correct as I get the correct output.
475
>
<
487
>
<
499
>
<
510
>
<
521