Difference between revisions of "Sumobotsclass"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
== Motor control code == | == Motor control code == | ||
− | < | + | <nowiki> |
+ | <nowiki>#include <PololuQTRSensors.h> </nowiki>//we're using the pololuQTR sensor library so we must attach it. | ||
+ | |||
+ | <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> | ||
+ | |||
#define motor1dir 8 //direction motor 2 | #define motor1dir 8 //direction motor 2 | ||
#define motor1speed 9 //pwm control motor 1 | #define motor1speed 9 //pwm control motor 1 | ||
Line 7: | Line 13: | ||
#define motor2speed 10 //pwm control motor 2 | #define motor2speed 10 //pwm control motor 2 | ||
#define ledpin 13 | #define ledpin 13 | ||
− | + | </nowiki> | |
void setup() { | void setup() { | ||
Line 42: | Line 48: | ||
</code> | </code> | ||
+ | |||
+ | //blinks an LED | ||
+ | |||
+ | void blink(int whatPin, int howManyTimes, int milliSecs) { | ||
+ | |||
+ | 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 | ||
---- | ---- |
Revision as of 10:52, 23 October 2011
Motor control code
<nowiki>#include <PololuQTRSensors.h> //we're using the pololuQTR sensor library so we must attach it.
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
unsigned int sensors[2];
- 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
</nowiki>
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);
}
//blinks an LED
void blink(int whatPin, int howManyTimes, int milliSecs) {
int i = 0;
for ( i = 0; i < howManyTimes; i++) {
digitalWrite(whatPin, HIGH);
delay(milliSecs/2);
digitalWrite(whatPin, LOW);
delay(milliSecs/2);
}
}// end blink
Need a Mechapad or some Protoboard and Patience