Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <Servo.h>
- double angle_rad = PI/180.0;
- double angle_deg = 180.0/PI;
- double steering;
- Servo servo_9;
- char inputchar = char();
- String string1 = String();
- String commandype = String();
- String commandvalue = String();
- void setup(){
- Serial.begin(57600);
- servo_9.attach(9); // init pin
- pinMode(2,OUTPUT);
- servo_9.write(90); // write to servo
- }
- void receive_bt() {
- while(!((( inputchar==';'))))
- {
- _loop();
- while(!(Serial.available()))
- {
- _loop();
- }
- inputchar= char(Serial.read());
- string1 += inputchar;
- }
- }
- void loop(){
- inputchar= "";
- string1= "";
- commandype= "";
- commandvalue= "";
- receive_bt();
- commandype= string1.substring(0, 1);
- commandvalue= string1.substring(1, string1.indexOf(';'));
- steering = (40) + commandvalue.toDouble();
- tone(2,262,50); // write to buzzer to indicate data received
- delay(50);
- Serial.print("New instructions recieved;");
- Serial.println(string1);
- Serial.println(commandype);
- Serial.println(commandvalue);
- Serial.println(steering);
- servo_9.write(steering); // write to servo
- inputchar= "";
- string1= "";
- }
- void _delay(float seconds){
- long endTime = millis() + seconds * 1000;
- while(millis() < endTime)_loop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement