Skip to content

Commit c2835b4

Browse files
committed
not working duplicate .h
1 parent 802d542 commit c2835b4

File tree

5 files changed

+130
-75
lines changed

5 files changed

+130
-75
lines changed

Arduino_Robot_Firmware.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#include "Arduino_Robot_Firmware.h"
2+
3+
4+
Arduino_Robot_Firmware::Arduino_Robot_Firmware(){
5+
// I2C internal bus
6+
wire = new TwoWire(I2C_1_SDA, I2C_1_SCL);
7+
8+
// RGB leds
9+
led1 = new RGBled(LED_1_RED,LED_1_GREEN,LED_1_BLUE);
10+
led2 = new RGBled(LED_2_RED,LED_2_GREEN,LED_2_BLUE);
11+
12+
// motors
13+
motor_left = new DCmotor(MOTOR_LEFT_A,MOTOR_LEFT_A_CH, MOTOR_LEFT_B, MOTOR_LEFT_B_CH,true);
14+
motor_right = new DCmotor(MOTOR_RIGHT_A,MOTOR_RIGHT_A_CH,MOTOR_RIGHT_B,MOTOR_RIGHT_B_CH);
15+
16+
// encoders
17+
encoder_left = new Encoder(TIM3);
18+
encoder_right = new Encoder(TIM5);
19+
20+
// color sensor
21+
apds9960 = new APDS9960(*wire,APDS_INT);
22+
}
23+
24+
int Arduino_Robot_Firmware::begin(){
25+
// setup alternate functions
26+
AF_Tim2_pwm();
27+
AF_Tim5_pins_encoder();
28+
AF_Tim3_pins_encoder();
29+
30+
// turn off leds
31+
led1->clear();
32+
led2->clear();
33+
34+
motor_left->begin();
35+
motor_right->begin();
36+
motor_left->stop();
37+
motor_right->stop();
38+
39+
encoder_left->begin();
40+
encoder_right->begin();
41+
42+
wire->begin();
43+
44+
beginAPDS();
45+
46+
return 0;
47+
}
48+
49+
50+
/******************************************************************************************************/
51+
/* Color sensor, APDS9960 */
52+
/******************************************************************************************************/
53+
54+
int Arduino_Robot_Firmware::beginAPDS(){
55+
pinMode(APDS_LED,OUTPUT);
56+
enableIlluminator();
57+
apds9960->begin();
58+
return 0;
59+
}
60+
61+
void Arduino_Robot_Firmware::updateAPDS(){
62+
if (apds9960->proximityAvailable()){
63+
bottom_proximity=apds9960->readProximity();
64+
}
65+
//digitalWrite(APDS_LED,HIGH);
66+
if (apds9960->colorAvailable()){
67+
apds9960->readColor(bottom_red,bottom_green,bottom_blue,bottom_clear);
68+
}
69+
//digitalWrite(APDS_LED,LOW);
70+
}
71+
72+
void Arduino_Robot_Firmware::setIlluminator(uint8_t value){
73+
digitalWrite(APDS_LED,value);
74+
}
75+
76+
void Arduino_Robot_Firmware::enableIlluminator(){
77+
setIlluminator(HIGH);
78+
}
79+
80+
void Arduino_Robot_Firmware::disableIlluminator(){
81+
setIlluminator(LOW);
82+
}
83+
84+
int Arduino_Robot_Firmware::getRed(){
85+
return bottom_red;
86+
}
87+
88+
int Arduino_Robot_Firmware::getGreen(){
89+
return bottom_green;
90+
}
91+
92+
int Arduino_Robot_Firmware::getBlue(){
93+
return bottom_blue;
94+
}
95+
96+
int Arduino_Robot_Firmware::getProximity(){
97+
return bottom_proximity;
98+
}

Arduino_Robot_Firmware.h

Lines changed: 12 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ class Arduino_Robot_Firmware{
1515
APDS9960 * apds9960;
1616
int bottom_red, bottom_green, bottom_blue, bottom_clear, bottom_proximity;
1717

18-
19-
2018
public:
2119
RGBled * led1;
2220
RGBled * led2;
@@ -27,82 +25,22 @@ class Arduino_Robot_Firmware{
2725
TwoWire * wire;
2826

2927

30-
Arduino_Robot_Firmware(){
31-
// I2C internal bus
32-
wire = new TwoWire(I2C_1_SDA, I2C_1_SCL);
33-
34-
// RGB leds
35-
led1 = new RGBled(LED_1_RED,LED_1_GREEN,LED_1_BLUE);
36-
led2 = new RGBled(LED_2_RED,LED_2_GREEN,LED_2_BLUE);
37-
38-
// motors
39-
motor_left = new DCmotor(MOTOR_LEFT_A,MOTOR_LEFT_A_CH, MOTOR_LEFT_B, MOTOR_LEFT_B_CH,true);
40-
motor_right = new DCmotor(MOTOR_RIGHT_A,MOTOR_RIGHT_A_CH,MOTOR_RIGHT_B,MOTOR_RIGHT_B_CH);
41-
42-
// encoders
43-
encoder_left = new Encoder(TIM3);
44-
encoder_right = new Encoder(TIM5);
45-
46-
// color sensor
47-
apds9960 = new APDS9960(*wire,APDS_INT);
48-
49-
}
50-
51-
int begin(){
52-
// setup alternate functions
53-
AF_Tim2_pwm();
54-
AF_Tim5_pins_encoder();
55-
AF_Tim3_pins_encoder();
56-
57-
// turn off leds
58-
led1->clear();
59-
led2->clear();
60-
61-
motor_left->begin();
62-
motor_right->begin();
63-
motor_left->stop();
64-
motor_right->stop();
65-
66-
encoder_left->begin();
67-
encoder_right->begin();
68-
69-
wire->begin();
70-
71-
pinMode(APDS_LED,OUTPUT);
72-
digitalWrite(APDS_LED,HIGH);
73-
apds9960->begin();
74-
75-
76-
77-
return 0;
78-
}
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-
}
28+
Arduino_Robot_Firmware();
9029

91-
int getRed(){
92-
return bottom_red;
93-
}
30+
int begin();
9431

95-
int getGreen(){
96-
return bottom_green;
97-
}
9832

99-
int getBlue(){
100-
return bottom_blue;
101-
}
10233

103-
int getProximity(){
104-
return bottom_proximity;
105-
}
34+
// Color sensor, APDS9960
35+
int beginAPDS(); // initialize all components required by color detection
36+
void updateAPDS(); // refresh data
37+
void setIlluminator(uint8_t value); // set white leds
38+
void enableIlluminator(); // white leds on
39+
void disableIlluminator(); // white leds off
40+
int getRed(); // red value 0-255
41+
int getGreen(); // green value 0-255
42+
int getBlue(); // blue value 0-255
43+
int getProximity(); // proximity value 0-127
10644
};
10745

10846
#endif

dcmotor.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,18 @@ class DCmotor{
3434
}
3535
htimX.Instance = _tim;
3636
frequency=_frequency;
37+
pinMode(MOTORS_ENABLE,OUTPUT);
3738
}
3839

3940
void begin(){
4041
timX = new HardwareTimer(htimX.Instance);
4142
timX->setPWM(chA, pinA, frequency, 0);
42-
timX->setPWM(chB, pinB, frequency, 0);
43+
timX->setPWM(chB, pinB, frequency, 0);
44+
digitalWrite(MOTORS_ENABLE,HIGH);
45+
}
46+
47+
void disable(){
48+
digitalWrite(MOTORS_ENABLE,LOW);
4349
}
4450

4551
void setSpeed(const int speed){

library.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=Arduino_Robot_Firmware
2+
version=0.0.1
3+
author=Arduino, Giovanni di Dio Bruno, Lucio Rossi
4+
maintainer=Arduino <[email protected]>
5+
sentence=Library and firmware for Arduino Robot
6+
paragraph=Robot Robot Robot
7+
category=Firmware
8+
url=https://github.com/gbr1/Arduino_Robot_Firmware
9+
includes=Arduino_Robot_Firmware.h
10+
depends=Arduino_APDS9960

pinout_definitions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#define __PINOUT_DEFINITIONS_H__
33

44

5+
6+
#define MOTORS_ENABLE PD2
7+
58
// Right Motor
69
#define ENC_RIGHT_TIMER TIM5
710
#define ENC_RIGHT_A PA0

0 commit comments

Comments
 (0)