|
|
| (10 intermediate revisions by 2 users not shown) |
| Line 1: |
Line 1: |
| == Motor control code ==
| | [[Sumobotclasscode]] |
| | |
| <nowiki>#include <PololuQTRSensors.h> //we're using the pololuQTR sensor library so we must attach it.</nowiki>
| |
| <nowiki>#define motor1dir 8 //direction motor 2</nowiki>
| |
| <nowiki>#define motor1speed 9 //pwm control motor 1</nowiki>
| |
| <nowiki>#define motor2dir 11 //direction motor 2</nowiki>
| |
| <nowiki>#define motor2speed 10 //pwm control motor 2</nowiki>
| |
| <nowiki>#define ledpin 13 //led pin </nowiki>
| |
| <nowiki>PololuQTRSensorsRC qtr((unsigned char[]) {19,18}, 2, 2000, 255); //declares two line sensors on pins 18 and 19 this corresponds to analog pins 4 and 5</nowiki>
| |
| <nowiki>unsigned int sensors[2];</nowiki>
| |
| | |
| void setup() { // put your setup code here, to run once:
| |
| //motor control outputs
| |
| pinMode(motor1dir, OUTPUT);
| |
| pinMode(motor1speed, OUTPUT);
| |
| pinMode(motor2dir, OUTPUT);
| |
| pinMode(motor2speed, OUTPUT);
| |
| // AV outputs
| |
| pinMode(ledPin, OUTPUT);
| |
| pinMode(buzzerPin, OUTPUT);
| |
| pinMode(irSensorPin, INPUT);
| |
| //Serial.begin(9600); // set up Serial library at 9600 bps for debugging
| |
| delay (3000); //wait for everything and for the match to start
| |
| blink(ledPin, 3, 100);
| |
| // blink the LED 3 times. This should happen only once.
| |
| // if you see the LED blink three times, it means that
| |
| // the module reset itself,. probably because the motor
| |
| // caused a brownout or a short.
| |
| } //end setup
| |
| | |
| | |
| void loop() { // put your main code here, to run repeatedly:
| |
| qtr.read(sensors);
| |
| analogWrite(motor2speed,255); //go all out
| |
| analogWrite(motor1speed,255);
| |
| digitalWrite(motor1dir, HIGH); //go forward
| |
| digitalWrite(motor2dir, HIGH);
| |
| delay(3000);
| |
| digitalWrite(motor1dir, LOW); //go backwards
| |
| digitalWrite(motor2dir, LOW);
| |
| delay(3000);
| |
| digitalWrite(motor1dir, HIGH); //go right
| |
| digitalWrite(motor2dir, LOW);
| |
| delay(3000);
| |
| digitalWrite(motor1dir, LOW); //go right
| |
| digitalWrite(motor2dir, HIGH);
| |
| delay(3000);
| |
| analogWrite(motor1speed,0); //stop
| |
| analogWrite(motor2speed,0);
| |
| delay(3000);
| |
| | |
| //Don't forget to enable the serial port in setup
| |
| Serial.print(analogRead(irSensorPin));
| |
| Serial.print(" r= ");
| |
| <nowiki>Serial.print(sensors[0]);//right</nowiki>
| |
| Serial.print(" l= ");
| |
| <nowiki>Serial.println(sensors[1]);//left </nowiki>
| |
| | |
| }
| |
| | |
| void blink(int whatPin, int howManyTimes, int milliSecs) {//blinks an LED
| |
| int i = 0;
| |
| <nowiki>for ( i = 0; i < howManyTimes; i++) {</nowiki>
| |
| digitalWrite(whatPin, HIGH);
| |
| delay(milliSecs/2);
| |
| digitalWrite(whatPin, LOW);
| |
| delay(milliSecs/2);
| |
| }
| |
| }// end blink
| |
| | |
|
| |
|
| | ---- |
|
| |
|
| ----
| |
|
| |
|
|
| |
|
| [http://dl.dropbox.com/u/253442/PololuQTRSensorsForArduino.zip QTR line sensors]
| |
|
| |
|
|
| |
|
|
| |
|
| ---- | | ---- |
|
| |
|
| |
|
|
| |
|
| Line 103: |
Line 32: |
| | Resistor||10k Ohm ||http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=CF14JT10K0CT-ND||5 | | | Resistor||10k Ohm ||http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=CF14JT10K0CT-ND||5 |
| |- | | |- |
| | Resistor||1k ohm||http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=CF14JT1K00CT-ND||2 | | | Resistor||1k ohm||http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=CF14JT1K00CT-ND||3 |
| |-
| |
| | Resistor||220ohm||http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=CF14JT220RCT-ND||2
| |
| |- | | |- |
| | Voltage regulator||7805||http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=LM7805CT-ND||1 | | | Voltage regulator||7805||http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=LM7805CT-ND||1 |
| Line 137: |
Line 64: |
| [[File:Mechapad.png]] | | [[File:Mechapad.png]] |
|
| |
|
| | --- files --- |
|
| |
|
| [http://dl.dropbox.com/u/253442/motordriver.zip eagle design files] | | [http://dl.dropbox.com/u/253442/motordriver.zip eagle design files] |
| | |
| | [http://dl.dropbox.com/u/253442/sumo_v3.svg Sumobot chasis file ] |
| | |
| | [http://dl.dropbox.com/u/253442/PololuQTRSensorsForArduino.zip QTR line sensors library] |