Adicionar bluetooth

This commit is contained in:
Duarte Milhinhos 2019-04-13 15:21:59 +01:00
parent 3abd9be011
commit fea5453eec

View File

@ -1,20 +1,37 @@
int pushButton = 2;
int recv = 0;
// the transistor which controls the motor will be attached to digital pin 9
int motorControl = 3;
// 0 FORWARD
// 1 BACKWARD
// 2 LEFT
// 3 RIGHT
// the setup routine runs once when you press reset:
void setup() {
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
// make the transistor's pin an output:
pinMode(motorControl, OUTPUT);
Serial.begin(115200); //initial the Serial
}
// the loop routine runs over and over again forever:
void loop() {
if (Serial.available()) {
analogWrite(motorControl, 0);
switch (Serial.read())
{
case 0:
Serial.println("MOVING FORWARD");
break;
case 1:
Serial.println("MOVING BACKWARD");
break;
case 2:
Serial.println("MOVING LEFT");
break;
case 3:
Serial.println("MOVING RIGHT");
break;
default:
Serial.println("INVALID INSTRUCTION");
}
}
}