I removed some lines that are not used at the moment anyway:
/*
*
* Siehe Arduino Cookbook: safari books online
* Sends station numbers to Raspberri: ok
* Receives max Numb of stations from Raspberry: nok
*/
const int MaxChars = 2;
char strValue[MaxChars+1];
int index = 0;
int maxNumb = 26;
int upperValue;
int lowerValue;
char ch;
int poti = 0;
int sensorValue = 10;
int tunerValue = 1;
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
{
sensorValue = analogRead(poti);
tunerValue = map(sensorValue, 0, 1023, 1, maxNumb);
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;
}
}
}
At least at the built in serial console it does what I want it to do:
- Starting with an initial value for the variable "maxNumb" (26) depending on the poti's position a number between 1 and 26 ist transfered via serial;
- If I enter a different value in the console, maxNumb is updated; if for instance I enter 50, by turning the knob I can produce numbers between 1 and 50: