Last active
August 29, 2015 14:00
-
-
Save nilsonpessim/11146739 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***************************************\ | |
** CARRINHO DE CONTROLE REMOTO ** | |
* * | |
** Nilsinho Pessim ** | |
\***************************************/ | |
#include <AFMotor.h> | |
AF_DCMotor m1(1); | |
AF_DCMotor m2(2); | |
int ledFarol = A0; | |
int somMP3 = A1; | |
int estadoFarol = LOW; | |
int estadoSom = LOW; | |
char acao; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(ledFarol,OUTPUT); | |
pinMode(somMP3, OUTPUT); | |
m1.run(RELEASE); | |
m2.run(RELEASE); | |
} | |
void loop() { | |
acao = Serial.read(); | |
if(acao == 'c'){ | |
estadoFarol = !estadoFarol; | |
} | |
if(acao == 'q'){ | |
estadoSom = !estadoSom; | |
} | |
// Carrinho pra Frente ... | |
if(acao=='w'){ | |
m1.run(FORWARD); | |
m1.setSpeed(140); | |
m2.run(FORWARD); | |
m2.setSpeed(140); | |
} | |
// Carrinho pra Tras ... | |
if(acao=='s'){ | |
m1.run(BACKWARD); | |
m1.setSpeed(100); | |
m2.run(BACKWARD); | |
m2.setSpeed(100); | |
} | |
// Carrinho pra Direita ... | |
if(acao=='d'){ | |
m1.run(FORWARD); | |
m1.setSpeed(100); | |
m2.run(RELEASE); | |
} | |
// Carrinho pra Esquerda ... | |
if(acao=='a'){ | |
m1.run(RELEASE); | |
m2.run(FORWARD); | |
m2.setSpeed(100); | |
} | |
// Carrinho Turbo ... | |
if(acao=='z'){ | |
m2.run(FORWARD); | |
m2.setSpeed(255); | |
m1.run(FORWARD); | |
m1.setSpeed(255); | |
} | |
// Carrinho Parar ... | |
if(acao=='x'){ | |
m2.run(RELEASE); | |
m1.run(RELEASE); | |
} | |
digitalWrite(ledFarol, estadoFarol); | |
digitalWrite(somMP3, estadoSom); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment