88#include " rgb_led.h"
99#include " dcmotor.h"
1010#include " motor_control.h"
11+ #include " Arduino_APDS9960.h"
1112
1213class Arduino_Robot_Firmware {
1314 private:
14-
15+ APDS9960 * apds9960;
16+ int bottom_red, bottom_green, bottom_blue, bottom_clear, bottom_proximity;
17+
18+
19+
1520 public:
1621 RGBled * led1;
1722 RGBled * led2;
1823 DCmotor * motor_left;
1924 DCmotor * motor_right;
2025 Encoder * encoder_left;
2126 Encoder * encoder_right;
27+ TwoWire * wire;
2228
2329
2430 Arduino_Robot_Firmware (){
31+ // I2C internal bus
32+ wire = new TwoWire (I2C_1_SDA, I2C_1_SCL);
33+
34+ // RGB leds
2535 led1 = new RGBled (LED_1_RED,LED_1_GREEN,LED_1_BLUE);
2636 led2 = new RGBled (LED_2_RED,LED_2_GREEN,LED_2_BLUE);
2737
38+ // motors
2839 motor_left = new DCmotor (MOTOR_LEFT_A,MOTOR_LEFT_A_CH, MOTOR_LEFT_B, MOTOR_LEFT_B_CH,true );
2940 motor_right = new DCmotor (MOTOR_RIGHT_A,MOTOR_RIGHT_A_CH,MOTOR_RIGHT_B,MOTOR_RIGHT_B_CH);
3041
42+ // encoders
3143 encoder_left = new Encoder (TIM3);
3244 encoder_right = new Encoder (TIM5);
3345
46+ // color sensor
47+ apds9960 = new APDS9960 (*wire,APDS_INT);
48+
3449 }
3550
3651 int begin (){
@@ -51,8 +66,43 @@ class Arduino_Robot_Firmware{
5166 encoder_left->begin ();
5267 encoder_right->begin ();
5368
69+ wire->begin ();
70+
71+ pinMode (APDS_LED,OUTPUT);
72+ digitalWrite (APDS_LED,HIGH);
73+ apds9960->begin ();
74+
75+
76+
5477 return 0 ;
5578 }
79+
80+ void updateAPDS (){
81+ if (apds9960->proximityAvailable ()){
82+ bottom_proximity=apds9960->readProximity ();
83+ }
84+ // digitalWrite(APDS_LED,HIGH);
85+ if (apds9960->colorAvailable ()){
86+ apds9960->readColor (bottom_red,bottom_green,bottom_blue,bottom_clear);
87+ }
88+ // digitalWrite(APDS_LED,LOW);
89+ }
90+
91+ int getRed (){
92+ return bottom_red;
93+ }
94+
95+ int getGreen (){
96+ return bottom_green;
97+ }
98+
99+ int getBlue (){
100+ return bottom_blue;
101+ }
102+
103+ int getProximity (){
104+ return bottom_proximity;
105+ }
56106};
57107
58108#endif
0 commit comments