Rover bot Analog input test program

So for all you geeks out there that want to see some badly assembled code, here you go.  I will clean it up later, right now it is full of comments and unnecessarily long and cumbersome. Mostly that is due to my lack of experiance.  But I am getting better.

 

Anyway, here is the code for verifying the analog input signals and measuring them to understand what they reflect in the real world.  (intentional pun)

// First robot code for input TEST of analog signals
//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 buttonL = 8;
int buttonR = 9;
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 sensorValueU = 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);
pinMode(buttonL, INPUT);
pinMode(buttonR, INPUT);

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

// Test LED outputs Leaving this in because it looks cool on startup

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);
Serial.begin(9600);
//open serial port and set it to a baud rate of 9600bps
}

void loop()
{
sensorValueL = analogRead(sensorPinL)/4;

sensorValueR = analogRead(sensorPinR)/4;
sensorValueU = analogRead(sensorPinU);
Serial.print(” Left Sensor Value”);
Serial.println(sensorValueL);
Serial.print(” Right Sensor Value”);
Serial.println(sensorValueR);
Serial.print(” Ultra sonic center Sensor Value”);
Serial.println(sensorValueU);
}

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: