Test code for rover bot.

Here is the code I wrote to test the outputs of the little rover bot.

// First robot code for LB2  OUTPUT TEST

//FUBARLABS

int button = 2; // momentary push button

int pwm_a = 3;  //PWM control for motor outputs 1 and 2 is on digital pin 3

int rLed = 5;  // Tricolored LEDs 5,6,7

int gLed = 6;

int bLed = 7;

int BsLed = 10;  //  Blue LED on Button

int pwm_b = 11;  //PWM control for motor outputs 3 and 4 is on digital pin 11

int dir_a = 12;  //direction control for motor outputs 1 and 2 is on digital pin 12

int dir_b = 13;  //direction control for motor outputs 3 and 4 is on digital pin 13

int sensorPinL = A2; //Infared sensor front left

int sensorPinR = A3; //Infared sensor front right

int sensorPinU = A4; // ultronic range finder

// varables used in program

int sensorValueL = 0;  // variable to store the value coming from the sensor

int sensorValueR = 0;  // variable to store the value coming from the sensor

int Limit = 480;

int Limit1 = 400;

int Limit2 = 300;

int x = 0;

int y = 0;

void setup()

{

pinMode(pwm_a, OUTPUT);  //Set control pins to be outputs

pinMode(pwm_b, OUTPUT);

pinMode(dir_a, OUTPUT);

pinMode(dir_b, OUTPUT);

pinMode(rLed, OUTPUT);

pinMode(gLed, OUTPUT);

pinMode(bLed, OUTPUT);

pinMode(BsLed, OUTPUT);

pinMode(button, INPUT);

analogWrite(pwm_a, 00);  //set both motors speed to 0

analogWrite(pwm_b, 00);

//  Test LED outputs turn each one on for 1/4 second.

digitalWrite(gLed, HIGH);

delay (250);

digitalWrite(gLed, LOW);

digitalWrite(rLed, HIGH);

delay (250);

digitalWrite(rLed, LOW);

digitalWrite(bLed, HIGH);

delay (250);

digitalWrite(bLed, LOW);

digitalWrite(BsLed, HIGH);

delay (250);

digitalWrite(BsLed, LOW);

delay (1000);

//Test motor output for a  Ramp up both motors slowly 0 2,4,8,16,32,64,128,255

//30ms between each step 0%-100% duty cycle

}

void loop()

{

digitalWrite(dir_a,HIGH);

digitalWrite(dir_b,HIGH);

for (int i=1; i <= 255; i=i*2){

analogWrite(pwm_a, i);

analogWrite(pwm_b, i);

delay(30); }

{delay (1000);

analogWrite(pwm_a,0);

analogWrite(pwm_b,0);

delay(1000);

}}

 

Note:  anything after the double slash // is not compiled into the program.  These are just comments to help me know what the hell I am attempting to do.

PF

Advertisements
Tagged , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: