Adicionar bluetooth
This commit is contained in:
parent
3abd9be011
commit
fea5453eec
39
motor.ino
39
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() {
|
||||
|
||||
analogWrite(motorControl, 0);
|
||||
if (Serial.available()) {
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue