Thank you. Process is load the sender arduino, move usb and load receiver arduino. Then leave usb in to read serial monitor on receiver arduino. Doing this process serial.available prints out 0. I set value = serial.available and printed value.
Also printed out serial.read and it seems all it reads is -1 for awhile then seems like a continuous loop of numbers without the pot even moving.
int potPin = 0; // select input pin
int val; // variable to store the value
void setup() {
Serial.begin(9600);
}
void loop()
{
val = analogRead(potPin); // read the value from the pot
Serial.print(val); //sends 1 byte
}
receiver
char string[4]; //can be 4, 8 is fine
byte var;
int index = 0;
boolean started=false;
boolean ended=false;
void setup()
{
Serial.begin(9600);
}
void loop()
{
int value = Serial.available();
Serial.println(value);
while(Serial.available() > 0)
{
var=Serial.read(); //read the character
if(var=='<') //not sure what to put in if statement to run until end
{
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';
}
}