From fea5453eecd3e77a93ecf219dcf3d6fc76a485b4 Mon Sep 17 00:00:00 2001 From: Duarte Milhinhos Date: Sat, 13 Apr 2019 15:21:59 +0100 Subject: [PATCH] Adicionar bluetooth --- motor.ino | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/motor.ino b/motor.ino index 8226024..0a5c4f8 100644 --- a/motor.ino +++ b/motor.ino @@ -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"); + } + + } }