Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- #include <SoftwareSerial.h>
- #include <Arduino.h>
- SoftwareSerial mySerial(11, 12);
- Servo myservo;
- String inString = "";
- unsigned long lastConnTime;
- unsigned long otherTime;
- int prev = 150;
- float vPow = 5;
- float r1 = 47000;
- float r2 = 10000;
- int lastEntry = 60;
- int throttle = 60;
- int voltcheck = 25;
- double b = 85; //Braking
- double n = 90; //Neutral
- double m = 120; //Accelerate
- void setup() {
- pinMode(13, OUTPUT);
- myservo.attach(5);
- mySerial.begin(9600);
- Serial.begin(4800);
- Serial.println("Bluetooth On");
- digitalWrite(13, LOW);
- }
- void loop() {
- if (mySerial.available() > 0) {
- char input = mySerial.read();
- if (isDigit(input)) {
- inString += input;
- }
- else {
- // as soon as the integer is done
- input = inString.toInt();
- throttle = check(input);
- lastEntry = throttle;
- myservo.write(throttle);
- inString = ""; // reset string
- lastConnTime = millis();
- }
- }
- else {
- if ((millis() - lastConnTime) > 3000) {
- Serial.println("CONNECTION TIMEOUT, BREAKING ");
- myservo.write(60);
- }else{
- myservo.write(lastEntry);
- }
- }
- Serial.println(myservo.read());
- }
- int check(int original) {
- return original;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement