Microbot Motor Control

posted in: Programming | 0
#define MOTOR_R_DIR 5 // Right motor direction pin
#define MOTOR_R_SPD 9 // Right motor speed pin - apply PWM signal (analog out) to this pin
#define MOTOR_L_DIR 6
#define MOTOR_L_SPD 10

#define FWD 0 // 0 = forward in our robot wiring
#define BWD 1 // 1 = backward in our robot wiring

In the above box, what you see are #defines, they allow you(the programmer) to give a name a constant value before compiling ]

Below, this box documentation explains how the #defines are set up to the corresponding values.

 

// The below defines are for the bit location of the corresponding buttons in our 8 bit encoded buttons variable received from the transmitter
#define A 0 // Right D pad up button
#define B 1 // Right D pad right button
#define C 2 // Right D pad down button
#define D 3 // Right D pad left button

#define UP 4 // Left D pad up button
#define RIGHT 5 // Left D pad right button
#define DOWN 6 // Left D pad down button
#define LEFT 7 // Left D pad left button

More #defines that are Robot Pin Constants

#define IR_LED_R 1 // IR LED Left used for reflective wall sensing
#define IR_LED_L 7 // IR LED Leuft used for reflective wall sensing
#define IR_38Khz 3 // IR LED 38khz Cathode connection

#define IR_SENSOR_R 15 // Right input from 38khz bandpass filter connected to IR PIN diode radio
#define IR_SENSOR_L 16 //

#define WALL_DETECTED 0 // Wall detected
#define WALL_NOT_DETECTED 1 // Wall not detected

 

This is the robot pin setup

pinMode(MOTOR_R_DIR, OUTPUT);
pinMode(MOTOR_R_SPD, OUTPUT);
pinMode(MOTOR_L_DIR, OUTPUT);
pinMode(MOTOR_L_SPD, OUTPUT);

 

LED robot set-up(green and red colored LED)

#define LED_R 13 // Red LED - Shared with SCK used for NRF24L01 Transceiver
#define LED_G 0 // Green LED - Shared with serial port radio pin
#define LED_B 4 // Blue LED

 

Basically, this is how you are able to interact (as a programmer) with your program. You can give values (numbers) a name.  When you do #defines, the compiler will replace references with a specific (defined, well-described) value when you are ready to compile (assemble) your code in order to operate your robot.  For example,

Leave a Reply