AplTVY3-B3-1sk-4T
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);
}