Skip to content

Commit c7fe613

Browse files
committed
servo, TIM11
1 parent 7eab495 commit c7fe613

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

examples/servo/servo.ino

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "Arduino_Robot_Firmware.h"
2+
3+
Arduino_Robot_Firmware robot;
4+
5+
void setup(){
6+
robot.begin();
7+
}
8+
9+
void loop(){
10+
for(int i=0; i<180; i++){
11+
robot.setServoA(i);
12+
robot.setServoB(i);
13+
delay(15);
14+
}
15+
delay(5000);
16+
}

src/Arduino_Robot_Firmware.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Arduino_Robot_Firmware::Arduino_Robot_Firmware(){
2121

2222
// color sensor
2323
apds9960 = new APDS9960(*wire,APDS_INT);
24+
25+
// servo
26+
servo_A = new Servo();
27+
servo_B = new Servo();
2428
}
2529

2630
int Arduino_Robot_Firmware::begin(){
@@ -44,6 +48,7 @@ int Arduino_Robot_Firmware::begin(){
4448
wire->begin();
4549

4650
beginAPDS();
51+
beginServo();
4752

4853
return 0;
4954
}
@@ -97,4 +102,22 @@ int Arduino_Robot_Firmware::getBlue(){
97102

98103
int Arduino_Robot_Firmware::getProximity(){
99104
return bottom_proximity;
105+
}
106+
107+
/******************************************************************************************************/
108+
/* RC Servo A & B */
109+
/******************************************************************************************************/
110+
111+
int Arduino_Robot_Firmware::beginServo(){
112+
servo_A->attach(SERVO_A);
113+
servo_B->attach(SERVO_B);
114+
return 0;
115+
}
116+
117+
void Arduino_Robot_Firmware::setServoA(int position){
118+
servo_A->write(position);
119+
}
120+
121+
void Arduino_Robot_Firmware::setServoB(int position){
122+
servo_B->write(position);
100123
}

src/Arduino_Robot_Firmware.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
#include "dcmotor.h"
99
#include "motor_control.h"
1010
#include "Arduino_APDS9960.h"
11+
#include <Servo.h>
1112

1213
class Arduino_Robot_Firmware{
1314
private:
1415
APDS9960 * apds9960;
1516
int bottom_red, bottom_green, bottom_blue, bottom_clear, bottom_proximity;
1617

18+
Servo * servo_A;
19+
Servo * servo_B;
20+
1721
public:
1822
RGBled * led1;
1923
RGBled * led2;
@@ -42,6 +46,12 @@ class Arduino_Robot_Firmware{
4246
int getGreen(); // green value 0-255
4347
int getBlue(); // blue value 0-255
4448
int getProximity(); // proximity value 0-127
49+
50+
51+
// Servo
52+
int beginServo(); // initialize Servo interfaces
53+
void setServoA(int position); // 0°-180° servo position
54+
void setServoB(int position); // 0°-180° servo position
4555
};
4656

4757
#endif

0 commit comments

Comments
 (0)