Telechargé par happyness maker

Nouveau document texte

publicité
#include <AFMotor.h>
//creates two objects to control the terminal 3 and 4 of motor shield
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
char command;
void setup()
{
Serial.begin(9600); //Set the baud rate to your Bluetooth module.
}
void loop() {
if (Serial.available() > 0) {
command = Serial.read();
Stop(); //initialize with motors stoped
//Change pin mode only if new command is different from previous.
//Serial.println(command);
switch (command) {
case 'F':
forward();
break;
case 'B':
back();
break;
case 'L':
left();
break;
case 'R':
right();
break;
case 'V':
t_left();
break;
case 'W':
t_right();
break;
}
}
}
void forward()
{
motor1.run(FORWARD); //rotate the motor clockwise
motor1.setSpeed(255); //Define maximum velocity
motor2.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(255); //Define maximum velocity
delay(2000);
}
void back()
{
motor1.run(BACKWARD);
motor1.setSpeed(255);
motor2.run(BACKWARD);
motor2.setSpeed(255);
delay(2000);
}
void left()
{
motor1.run(FORWARD);
motor1.setSpeed(255);
motor2.run(BACKWARD);
motor2.setSpeed(255);
delay(1000);
}
void right()
{
motor1.run(BACKWARD);
motor1.setSpeed(255);
motor2.run(FORWARD);
motor2.setSpeed(255);
delay(1000);
}
void t_right()
{
motor2.run(FORWARD);
motor2.setSpeed(255); //Define maximum velocity
motor1.run(BACKWARD);
motor1.setSpeed(255);
delay(1000);
}
void t_left()
{
motor1.run(FORWARD);
motor1.setSpeed(255);
motor2.run(BACKWARD);
motor2.setSpeed(255); //Define maximum velocity
delay(1000);
}
void Stop()
{
motor2.run(RELEASE); //turn motor1 off motor1.setSpeed(0);
motor2.run(RELEASE); //turn motor2 off
motor2.setSpeed(0);
}
Téléchargement
Random flashcards
Commune de paris

0 Cartes Edune

Ce que beaucoup devaient savoir

0 Cartes Jule EDOH

Algorithme

3 Cartes trockeur29

Créer des cartes mémoire