sender
int potPin = 0; // select input pin
int val = 0; // variable to store the value
void setup() {
Serial.begin(9600);
}
void loop()
{
val = analogRead(potPin); // read the value from the pot
//val = map(val, 0 1023, 0, 180);
Serial.println( val );
delay(1);
}
receiver
//read till end of packet
char string[8];
int x;
int index;
boolean started=false;
boolean ended=false;
void setup()
{
Serial.begin(9600);
}
void loop()
{
while(Serial.available() >= 0) //since 0-1023
{
x=Serial.read(); //read the character
if(x=='<') //not sure what to put in if statement to run until end
{
started = true;
index=0;
string[index]='\0';
}
else if(x=='>')
{
ended = true;
}
else if(started)
{
string[index]=x;
index++;
string[index]='\0';
string[index]=x; //store character
}
//x = Serial.read(); //read another string
}
if(started && ended)
{
//convert portion of string to integer representation
int val=atoi(string);
Serial.println(val);
//next time
started = false;
ended = false;
index = 0;
string[index]='\0';
}
}