This repository has been archived by the owner on Feb 11, 2019. It is now read-only.
/
teste_motor.ino
98 lines (84 loc) · 2.22 KB
/
teste_motor.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!
#include <AFMotor.h>
#define VELOCITY 255 // velocidade de rotaçao das rodas
#define STEP_SIZE 100 // delay em milissegundos
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("DEMO CONTROLE BT!");
// Ajusta a velocidade dos motores
motor1.setSpeed(VELOCITY);
motor2.setSpeed(VELOCITY);
motor3.setSpeed(VELOCITY);
motor4.setSpeed(VELOCITY);
delay(1000);
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
}
void loop() {
uint8_t i ;
if (Serial.available() > 0) {
incomingByte = Serial.read();
Serial.print((char)incomingByte);
switch((char)incomingByte) {
case 'w':
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
delay(STEP_SIZE);
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
break;
case 's':
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(STEP_SIZE);
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
break;
case 'a':
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(STEP_SIZE);
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
break;
case 'd':
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
delay(STEP_SIZE);
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
break;
default:
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
break;
}
}
}