1- // ####################################################################################
2- // This library is used for communicating with the GoPiGo.
3- // http://www.dexterindustries.com/GoPiGo/
1+ // ####################################################################################
2+ // This library is used for communicating with the GoPiGo.
3+ // http://www.dexterindustries.com/GoPiGo/
44// History
55// ------------------------------------------------
66// Date Comments
4343#include <stdbool.h>
4444
4545extern int fd ;
46- extern char * fileName ;
47- extern int address ;
46+ extern const char * fileName ;
47+ extern const int address ;
4848extern unsigned char w_buf [5 ],r_buf [32 ];
49- extern unsigned long reg_addr ;
49+ extern const unsigned long reg_addr ;
50+ const bool LED_L = 1 ,LED_R = 0 ;
5051
5152#define fwd_cmd 119 //Move forward with PID
5253#define motor_fwd_cmd 105 //Move forward without PID
@@ -72,7 +73,7 @@ extern unsigned long reg_addr;
7273#define en_enc_cmd 51 //Enable the encoders
7374#define dis_enc_cmd 52 //Disable the encoders
7475#define read_enc_status_cmd 53 //Read encoder status
75- #define en_servo_cmd 61 //Enable the servo's
76+ #define en_servo_cmd 61 //Enable the servo's
7677#define dis_servo_cmd 60 //Disable the servo's
7778#define set_left_speed_cmd 70 //Set the speed of the right motor
7879#define set_right_speed_cmd 71 //Set the speed of the left motor
@@ -82,7 +83,7 @@ extern unsigned long reg_addr;
8283#define enc_read_cmd 53 //Read encoder values
8384#define trim_test_cmd 30 //Test the trim values
8485#define trim_write_cmd 31 //Write the trim values
85- #define trim_read_cmd 32
86+ #define trim_read_cmd 32
8687
8788#define digital_write_cmd 12 //Digital write on a port
8889#define digital_read_cmd 13 //Digital read on a port
@@ -103,7 +104,7 @@ char read_byte(void);
103104//Get voltage
104105float volt (void );
105106
106- //Sleep in ms
107+ //Sleep in ms
107108void pi_sleep (int t );
108109
109110//Control Motor 1
@@ -124,7 +125,7 @@ int bwd(void);
124125//Move GoPiGo back without PID control
125126int motor_bwd (void );
126127
127- //Turn GoPiGo Left slow (one motor off, better control)
128+ //Turn GoPiGo Left slow (one motor off, better control)
128129int left (void );
129130
130131//Rotate GoPiGo left in same position (both motors moving in the opposite direction)
@@ -184,6 +185,12 @@ int us_dist(int pin);
184185// speed -> pointer to array of 2 bytes [motor1, motor2], allocated before
185186void read_motor_speed (unsigned char * speed );
186187
188+ //Turn led on or off
189+ // arg:
190+ // l_id: 1 for left LED and 0 for right LED
191+ // onoff: 0 off, 1 on
192+ int led_toggle (int l_id , bool onoff );
193+
187194//Turn led on
188195// arg:
189196// l_id: 1 for left LED and 0 for right LED
0 commit comments