Got to to where when it is not an infinite loop at first but once I turn past a certain point it turns into an infinite loop until I turn it back. Isn't showing values 0-1023, still range I mentioned previously.
sender
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(">");
}
}
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.print(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';
}
}