Hello I'm back again.
This time I want to know if its possible to send variables to a sketch using the Serial Monitor.
So when I declare this:
int YourBulletCount = 0;
I can send the value of this variable to the board using the serial monitor.
Hello I'm back again.
This time I want to know if its possible to send variables to a sketch using the Serial Monitor.
So when I declare this:
int YourBulletCount = 0;
I can send the value of this variable to the board using the serial monitor.
This time I want to know if its possible to send variables to a sketch using the Serial Monitor.
No, but it is possible to send data to a sketch that it interprets as a value to store in a variable.
I can send the value of this variable to the board using the serial monitor.
That is possible.
How is the Arduino to know what variable to store the value in? Will it always be the same one? How will the Arduino know when the end of the value has arrived?
Thanx for the reply,
But could you please explain me how to do this?
But could you please explain me how to do this?
Sure. Once you answer all of my questions.
If you want to send the value "<12>" to the Arduino and have it store the value 12 in a variable, how is it to know which one?
If you want to send "<x=23.5>", and have it store the value 23.5 in the variable named x, assuming that there is one, that's a different story.
simple code that sends a string of characters to the arduino (usually 500 to 2500 range), which are captured as a String variable (readString), the converted to an integer variable using readString.toInt().
// zoomkat 10-14-11 serial servo test
// use a microseconds value like 1500 in serial monitor
// for IDE 0022 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(1500); //set initial servo position if desired
myservo.attach(7); //the pin for the servo control
Serial.println("servo-test-22"); // 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); // allow buffer to fill with next character
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured string
myservo.writeMicroseconds(readString.toInt()); //convert readString to number for servo
readString=""; //empty for next input
}
}