int x; // integer x decalaraion
char p, *l; // declaration for charecter p and pointer to charecter l
void setup()
{
Serial.begin(115200); // begin serial communication
Serial.println("TEsT"); // debug string
}
void loop() //begin main loop
{
if(Serial.available()>0) //check if there is charecter in the serial buffer
{
p=Serial.read(); // read the serial data which is character store it in p
*l=p; // store address of character value p in char pointer l
x=atoi(l); // integer x equals ascii to integer converted l
delay(500);
Serial.println(x);
}
}
the program above only reads an int but i want it to read values such as 123.
i would really appreciate if someone could help me improve this program.
// zoomkat 10-4-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// for IDE 0019 and later
// 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.writeMicroseconds(2000); //set initial servo position if desired
myservo.attach(7); //the pin for the servo control
Serial.println("servo-test-21"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
delay(1);
if (Serial.available() >0) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
}
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured string
int n;
char carray[6]; //converting string to number
readString.toCharArray(carray, sizeof(carray));
n = atoi(carray);
myservo.writeMicroseconds(n); // for microseconds
//myservo.write(n); //for degees 0-180
readString="";
}
}