Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo servoLeft;
- Servo servoRight;
- String readString;
- void sendInfo(int time, int speed);
- void Setup();
- void loop();
- void setup()
- {
- Serial.begin(9600);
- servoLeft.writeMicroseconds(1500);
- servoRight.writeMicroseconds(1500);
- servoLeft.attach(13);
- servoRight.attach(12);
- }
- void loop()
- {
- /* Serial.begin(9600);
- servoLeft.writeMicroseconds(1500);
- servoRight.writeMicroseconds(1500);
- servoLeft.attach(13);
- servoRight.attach(12);*/
- Serial.println("WheelSet");
- int time;
- int speed;
- delay(1000);
- //Gets the time
- Serial.print("Please enter the time:");
- int k;
- readString="";
- while ((k = Serial.read()) != '\n')
- {
- if (k != -1)
- readString += (char) k;
- Serial.print((char) k);
- }
- if (readString.length() > 0)
- {
- Serial.println(readString); //so you can see the captured string
- time = readString.toInt(); //convert readString into a number
- time = time * 1000;
- Serial.print("Time: ");
- Serial.print(time);
- Serial.println("ms");
- }
- //Gets the speed
- speed=0;
- Serial.println("Please enter the speed:");
- int x;
- readString="";
- while ((k = Serial.read()) != '\n')
- {
- if (k != -1)
- readString += (char) k;
- Serial.print((char) k);
- }
- if (readString.length() > 0)
- {
- //Serial.println(readString); //so you can see the captured string
- speed = readString.toInt(); //convert readString into a number
- }
- //Sends the info
- // auto select appropriate value, copied from someone elses code.
- if(speed>=200)
- {
- Serial.print("writing Microseconds: ");
- Serial.println(speed);
- servoLeft.writeMicroseconds(speed);
- servoRight.writeMicroseconds(speed);
- }
- delay(time);
- servoLeft.detach();
- servoRight.detach();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement