Thanks in advance for helping me with this issue. Before starting the loop (where I'm reading some analogic inputs), I would like to receive a value from the Serial port, and depending on this value, I will change the sampling frequency, so then I can start reading the inputs.
The problem is that I dont know how to make my Arduino waits until receiving the value from the Serial port with Serial.read.
Thanks in advance for helping me with this issue. Before starting the loop (where I’m reading some analogic inputs), I would like to receive a value from the Serial port, and depending on this value, I will change the sampling frequency, so then I can start reading the inputs.
Very simple serial character capture and conversion of the captured characters into a number for use in servo control.
//zoomkat 7-30-10 serial servo test
//type servo position 0 to 180 in serial monitor
// Powering a servo from the arduino usually *DOES NOT WORK*.
String readString;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
Serial.begin(9600);
myservo.attach(9);
Serial.println("servo-test"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the String readString
delay(2); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured String
int n = readString.toInt(); //convert readString into a number
myservo.write(n);
readString="";
}
}
Have a look at the examples in serial input basics. They allow you to capture serial input into a char array where you can do whatever you want with it.