Sumobotsclass: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
== Motor control code == | |||
<nowiki> | |||
#define motor1dir 8 //direction motor 2 | |||
#define motor1speed 9 //pwm control motor 1 | |||
#define motor2dir 11 //direction motor 2 | |||
#define motor2speed 10 //pwm control motor 2 | |||
#define ledpin 13 | |||
void setup() { | |||
// put your setup code here, to run once: | |||
pinMode(motor1dir, OUTPUT); | |||
pinMode(motor1speed, OUTPUT); | |||
pinMode(motor2dir, OUTPUT); | |||
pinMode(motor2speed, OUTPUT); | |||
pinMode(ledpin, OUTPUT); | |||
digitalWrite(ledpin, HIGH); | |||
delay(3000); | |||
digitalWrite(ledpin, LOW); | |||
} | |||
void loop() { | |||
// put your main code here, to run repeatedly: | |||
analogWrite(motor2speed,255); //go all out | |||
analogWrite(motor1speed,255); | |||
digitalWrite(motor1dir, HIGH); //go this way | |||
digitalWrite(motor2dir, HIGH); | |||
delay(3000); | |||
digitalWrite(motor1dir, LOW); //go opposite way | |||
digitalWrite(motor2dir, LOW); | |||
delay(3000); | |||
analogWrite(motor1speed,0); //stop | |||
analogWrite(motor2speed,0); | |||
delay(3000); | |||
} | |||
</nowiki> | |||
---- | |||
[http://dl.dropbox.com/u/253442/PololuQTRSensorsForArduino.zip QTR line sensors] | |||
---- | |||
Need a Mechapad or some Protoboard and Patience | Need a Mechapad or some Protoboard and Patience | ||
{| {{table}} | {| {{table}} | ||
| Line 5: | Line 61: | ||
| align="center" style="background:#f0f0f0;"|'''where''' | | align="center" style="background:#f0f0f0;"|'''where''' | ||
| align="center" style="background:#f0f0f0;"|'''amount per bot''' | | align="center" style="background:#f0f0f0;"|'''amount per bot''' | ||
|- | |- | ||
| motor driver||h-bridge||http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=296-9911-5-ND||1 | | motor driver||h-bridge||http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=296-9911-5-ND||1 | ||
| Line 58: | Line 112: | ||
[http://dl.dropbox.com/u/253442/motordriver.zip eagle design files] | [http://dl.dropbox.com/u/253442/motordriver.zip eagle design files] | ||
Revision as of 23:49, 22 October 2011
Motor control code
#define motor1dir 8 //direction motor 2 #define motor1speed 9 //pwm control motor 1 #define motor2dir 11 //direction motor 2 #define motor2speed 10 //pwm control motor 2 #define ledpin 13 void setup() { // put your setup code here, to run once: pinMode(motor1dir, OUTPUT); pinMode(motor1speed, OUTPUT); pinMode(motor2dir, OUTPUT); pinMode(motor2speed, OUTPUT); pinMode(ledpin, OUTPUT); digitalWrite(ledpin, HIGH); delay(3000); digitalWrite(ledpin, LOW); } void loop() { // put your main code here, to run repeatedly: analogWrite(motor2speed,255); //go all out analogWrite(motor1speed,255); digitalWrite(motor1dir, HIGH); //go this way digitalWrite(motor2dir, HIGH); delay(3000); digitalWrite(motor1dir, LOW); //go opposite way digitalWrite(motor2dir, LOW); delay(3000); analogWrite(motor1speed,0); //stop analogWrite(motor2speed,0); delay(3000); }
Need a Mechapad or some Protoboard and Patience
