//bluetooth controlled boat. //includes a servo for the rudder (or steering plane) //includes a motor for the fan //commands come from MIT App builder app on an android phone //Kif Scheuer 2016 //This is in the public domain #include #include #include #include "utility/Adafruit_MS_PWMServoDriver.h" Adafruit_MotorShield AFMS = Adafruit_MotorShield(); String readString; Servo myservo; Adafruit_DCMotor *myturb3 = AFMS.getMotor(3); void setup() { Serial.begin(9600); AFMS.begin(); myservo.attach(9); myturb3->setSpeed(255); myturb3->run(FORWARD); myturb3->run(RELEASE); myservo.write(80); } void loop() { while ( Serial.available() ) { // While there is data in the buffer delay( 3 ); char c = Serial.read(); readString += c; // build the string - ÒonÓ or ÒoffÓ } if ( readString.length() > 0 ) { if ( readString == "Stop" ) { myturb3->run(RELEASE); myservo.write(80); } if ( readString == "BackwardStraight" ) { myturb3->setSpeed(255); myturb3->run(FORWARD); myservo.write(80); } if ( readString == "BackwardLeft" ) { myturb3->setSpeed(255); myturb3->run(FORWARD); myservo.write(130); } if ( readString == "BackwardRight" ) { myturb3->setSpeed(255); myturb3->run(FORWARD); myservo.write(25); } if ( readString == "ForwardStraight" ) { myturb3->setSpeed(255); myturb3->run(BACKWARD); myservo.write(80); } if ( readString == "ForwardLeft" ) { myturb3->setSpeed(255); myturb3->run(BACKWARD); myservo.write(130); } if ( readString == "ForwardRight" ) { myturb3->setSpeed(255); myturb3->run(BACKWARD); myservo.write(25); } readString = ""; } }