#include <LiquidCrystal.h>
const byte PIN_BUTTON_RIGHT = 8;
const byte PIN_BUTTON_UP = 9;
const byte PIN_BUTTON_DOWN = 10;
const byte PIN_BUTTON_LEFT = 11;
const byte PIN_BUTTON_TEMP = 12;
float tempc;
int temppin=0;
LiquidCrystal lcd(A4,A5,12,11,10,9);
int sirene,Buzzer=6,LED=7;
int RECV_PIN=2, motor1_1=3, motor1_2=4, motor2_1=5, motor2_2=6,ledfarol=7;
void setup() {
Serial.begin(9600);
Serial.println("Simple Adafruit Motor Shield sketch");
pinMode(PIN_BUTTON_RIGHT, INPUT);
digitalWrite(PIN_BUTTON_RIGHT, HIGH);
pinMode(PIN_BUTTON_LEFT, INPUT);
digitalWrite(PIN_BUTTON_LEFT, HIGH);
pinMode(PIN_BUTTON_UP, INPUT);
digitalWrite(PIN_BUTTON_UP, HIGH);
pinMode(PIN_BUTTON_DOWN, INPUT);
digitalWrite(PIN_BUTTON_DOWN, HIGH);
pinMode(PIN_BUTTON_TEMP, INPUT);
digitalWrite(PIN_BUTTON_TEMP, HIGH);
lcd.begin(16, 2);
pinMode(motor1_1,OUTPUT);
pinMode(motor1_2,OUTPUT);
pinMode(motor2_1,OUTPUT);
pinMode(motor2_2,OUTPUT);
pinMode(LED,OUTPUT);
pinMode(A1,OUTPUT);
pinMode(A2,OUTPUT);
pinMode(A3,OUTPUT);
pinMode(A4,OUTPUT);
pinMode(A5,OUTPUT);
pinMode(ledfarol,OUTPUT);
pinMode(Buzzer,OUTPUT);
}
void loop() {
if (digitalRead(PIN_BUTTON_UP) == LOW) { //frente
lcd.setCursor(0,0);
lcd.print("Botao 1");
lcd.setCursor(0,1);
lcd.print("Frente");
digitalWrite(motor2_2,LOW);
digitalWrite(motor1_2,LOW);
digitalWrite(motor1_1,HIGH);
digitalWrite(motor2_1,HIGH);
}
else
{
//button is not pressed
}
if (digitalRead(PIN_BUTTON_DOWN) == LOW) { //tras
lcd.setCursor(0,0);
lcd.print("Botao 2");
lcd.setCursor(0,1);
lcd.print("Ré");
digitalWrite(motor2_1,LOW);
digitalWrite(motor1_1,LOW);
digitalWrite(motor1_2,HIGH);
digitalWrite(motor2_2,HIGH);
}
else
{
//button is not pressed
}
/*if (digitalRead(PIN_BUTTON_UP) == LOW) { //parar
lcd.setCursor(0,0);
lcd.print("Botao 3");
lcd.setCursor(0,1);
lcd.print("Parar");
digitalWrite(motor2_2,LOW);
digitalWrite(motor1_2,LOW);
digitalWrite(motor2_1,LOW);
digitalWrite(motor1_1,LOW);
else
//button is not pressed
}*/
if (digitalRead(PIN_BUTTON_LEFT) == LOW) { //ESQUERDA
lcd.setCursor(0,0);
lcd.print("Botao 4");
lcd.setCursor(0,1);
lcd.print("Esquerda");
digitalWrite(motor2_1,LOW);
digitalWrite(motor1_2,LOW);
digitalWrite(motor1_1,HIGH);
digitalWrite(motor2_2,HIGH);
}
else
{
//button is not pressed
}
if (digitalRead(PIN_BUTTON_RIGHT) == LOW) { //DIREITA
lcd.setCursor(0,0);
lcd.print("Botao 5");
lcd.setCursor(0,1);
lcd.print("Direita");
digitalWrite(motor2_2,LOW);
digitalWrite(motor1_1,LOW);
digitalWrite(motor1_2,HIGH);
digitalWrite(motor2_1,HIGH);
}
else
{
//button is not pressed
}
if (digitalRead(PIN_BUTTON_TEMP) == LOW) { //temp
tempc=analogRead(temppin);
tempc=((5.0*tempc*100)/1024);
Serial.println(tempc);
lcd.setCursor(0,0);
lcd.print("Temperatura");
lcd.setCursor(0,1);
lcd.print(tempc);
}
else
{
//button is not pressed
}
}
Nenhum comentário:
Postar um comentário