Skip to content

Commit 5ff98bb

Browse files
committed
encoder in robot class
1 parent ac0b0bf commit 5ff98bb

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

Arduino_Robot_Firmware.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class Arduino_Robot_Firmware{
1717
RGBled * led2;
1818
DCmotor * motor_left;
1919
DCmotor * motor_right;
20+
Encoder * encoder_left;
21+
Encoder * encoder_right;
2022

2123

2224
Arduino_Robot_Firmware(){
@@ -26,6 +28,9 @@ class Arduino_Robot_Firmware{
2628
motor_left = new DCmotor(MOTOR_LEFT_A,MOTOR_LEFT_A_CH, MOTOR_LEFT_B, MOTOR_LEFT_B_CH,true);
2729
motor_right = new DCmotor(MOTOR_RIGHT_A,MOTOR_RIGHT_A_CH,MOTOR_RIGHT_B,MOTOR_RIGHT_B_CH);
2830

31+
encoder_left = new Encoder(TIM3);
32+
encoder_right = new Encoder(TIM5);
33+
2934
}
3035

3136
int begin(){
@@ -43,6 +48,9 @@ class Arduino_Robot_Firmware{
4348
motor_left->stop();
4449
motor_right->stop();
4550

51+
encoder_left->begin();
52+
encoder_right->begin();
53+
4654
return 0;
4755
}
4856
};

examples/simple/simple.ino

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
11
#include "Arduino_Robot_Firmware.h"
22

3+
34
Arduino_Robot_Firmware robot;
45

56
void setup(){
6-
robot.begin();
7+
Serial.begin(115200);
8+
robot.begin();
79
}
810

911
void loop(){
10-
robot.led1->setRed(1);
11-
delay(1000);
12-
robot.led1->setRed(0);
13-
delay(1000);
12+
robot.motor_left->setSpeed(4095);
13+
robot.motor_right->setSpeed(4095);
14+
Serial.print(robot.encoder_left->getCount());
15+
Serial.print("\t");
16+
Serial.print(robot.encoder_right->getCount());
17+
Serial.print("\n");
18+
19+
robot.led1->set(HIGH,LOW,LOW);
20+
robot.led2->set(LOW,LOW,HIGH);
21+
delay(1000);
22+
23+
robot.motor_left->setSpeed(-4095);
24+
robot.motor_right->setSpeed(4095);
25+
Serial.print(robot.encoder_left->getCount());
26+
Serial.print("\t");
27+
Serial.print(robot.encoder_right->getCount());
28+
Serial.print("\n");
29+
30+
robot.led1->set(LOW,LOW,HIGH);
31+
robot.led2->set(HIGH,LOW,LOW);
32+
delay(1000);
1433
}

0 commit comments

Comments
 (0)