I turn the pot all the way to the right side ... so after sending the value 40, variable maxNumb should get that value and arduino should send this value back to the computer - but this does not happen:
root@raspberrypi:/home/pi# cat /dev/ttyACM0
26
26
26
26
26 is the value that was initially set to the varable "maxNumb" in my sketch.
Here is the code of whole sketch:
/*
*
* Siehe Arduino Cookbook: safari books onlin
* Uebertraegt Sendernummer zum Radio
*/
const int MaxChars = 2;
char strValue[MaxChars+1];
int index = 0;
int maxNumb = 26 ;
int value;
int upperValue;
int lowerValue;
char ch;
void setup() // run once, when the sketch starts
{
Serial.begin(9600); // set up Serial library at 9600 bps
}
void loop() // run over and over again
{
int sensorValue = analogRead(A0);
do
{
int sensorValue = analogRead(A0);
delay(100);
int upperValue = sensorValue + 2;
int lowerValue = sensorValue - 2;
} while (sensorValue < upperValue && sensorValue > lowerValue);
int tunerValue = map(sensorValue, 0, 1023, 1, maxNumb);
if (tunerValue < 10)
{
Serial.print(0);
}
Serial.println(tunerValue,DEC);
delay(250);
if (Serial.available())
{
char ch = Serial.read();
if(index < MaxChars && ch >= '0' && ch <= '9'){
strValue[index++] = ch; // add the ASCII character to the string;
}
else
{
// here when buffer full or on the first non digit
strValue[index] = 0; // terminate the string with a 0
maxNumb = atoi(strValue); // use atoi to convert the string to an int
index = 0;
}
}
}