AplTVY3-B3-1sk-4T: Porovnání verzí
Řádek 9: | Řádek 9: | ||
==se pohyboval vpřed do vzdálenosti 1m == | ==se pohyboval vpřed do vzdálenosti 1m == | ||
<source lang="Cpp"> | |||
int motor_left[] = {6, 7} | |||
int | int motor_right[] = {8, 10} | ||
void setup() { | |||
drive_forward(); | Serial.begin(9600); | ||
delay(6200); | int i; | ||
motor_stop(); | for(i = 0; i < 2; i++){ | ||
Serial.println("1"); | pinMode(motor_left[i], OUTPUT); | ||
pinMode(motor_right[i], OUTPUT); | |||
drive_forward(); | |||
delay(6200); | |||
motor_stop(); | |||
Serial.println("1"); | |||
} | } | ||
} | } | ||
void loop() { | void loop() { | ||
} | } | ||
void motor_stop(){ | void motor_stop(){ | ||
digitalWrite(motor_left[0], LOW); | digitalWrite(motor_left[0], LOW); | ||
digitalWrite(motor_left[1], LOW); | digitalWrite(motor_left[1], LOW); | ||
digitalWrite(motor_right[0], LOW); | digitalWrite(motor_right[0], LOW); | ||
digitalWrite(motor_right[1], LOW); | digitalWrite(motor_right[1], LOW); | ||
} | } | ||
void drive_forward(){ | void drive_forward(){ | ||
digitalWrite(motor_left[0], HIGH); | digitalWrite(motor_left[0], HIGH); | ||
digitalWrite(motor_left[1], LOW); | digitalWrite(motor_left[1], LOW); | ||
digitalWrite(motor_right[0], HIGH); | digitalWrite(motor_right[0], HIGH); | ||
digitalWrite(motor_right[1], LOW); | digitalWrite(motor_right[1], LOW); | ||
}< | } | ||
</source> | |||
{{#widget:YouTube|id=1WMYtVgvqE8|Video jízdy vpřed|right}} | |||
==se pohyboval vpřed ve čtyřúhelníku o straně cca 0,5m == | ==se pohyboval vpřed ve čtyřúhelníku o straně cca 0,5m == |
Verze z 4. 6. 2012, 17:19
HW: Arduino realizace: Maxa David Charvát Jakub Lukáš Jílek
Úkoly:
- Sestavte robota, napište program a vyzkoušejte proto, aby robot:
se pohyboval vpřed do vzdálenosti 1m
int motor_left[] = {6, 7}
int motor_right[] = {8, 10}
void setup() {
Serial.begin(9600);
int i;
for(i = 0; i < 2; i++){
pinMode(motor_left[i], OUTPUT);
pinMode(motor_right[i], OUTPUT);
drive_forward();
delay(6200);
motor_stop();
Serial.println("1");
}
}
void loop() {
}
void motor_stop(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], LOW);
digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], LOW);
}
void drive_forward(){
digitalWrite(motor_left[0], HIGH);
digitalWrite(motor_left[1], LOW);
digitalWrite(motor_right[0], HIGH);
digitalWrite(motor_right[1], LOW);
}
se pohyboval vpřed ve čtyřúhelníku o straně cca 0,5m
int motor_left[] = {6, 7};
int motor_right[] = {8, 10};
void setup() {
Serial.begin(9600);
int i;
for(i = 0; i < 2; i++){
pinMode(motor_left[i], OUTPUT);
pinMode(motor_right[i], OUTPUT);
}
}
void loop() {}
drive_forward();
delay(3200);
motor_stop();
Serial.println("1");
turn_left();
delay(420);
motor_stop();
Serial.println("3");
motor_stop();
delay(1000);
motor_stop();
Serial.println("5");
}
void motor_stop(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], LOW);
digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], LOW);
delay(25);
}
void drive_forward(){
digitalWrite(motor_left[0], HIGH);
digitalWrite(motor_left[1], LOW);
digitalWrite(motor_right[0], HIGH);
digitalWrite(motor_right[1], LOW);
}
void turn_left(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], HIGH);
digitalWrite(motor_right[0], HIGH);
digitalWrite(motor_right[1], LOW);
}