#include <Arduino.h>
#include <Wire.h>
// #include <Adafruit_GFX.h>
#include <DabbleESP32.h>
#include <ESP32Servo.h> // Incluindo biblioteca Servo Esp32
#define CUSTOM_SETTINGS
#define INCLUDE_LEDCONTROL_MODULE
#define Farol 2
#define Lant_Freio 4
#define Buzina 5
#define PonteH1 18
#define PonteH2 19
#define LedSetDir 12
#define LedSetEsq 13
#define Pwm 0
#define Direcao 27
const int Pwm_Char = 0;
const int Pwm_Freq = 500;
const int Pwm_Res = 8;
Servo servo; // Criando Objeto Servo, para controle do Servo Motor
uint32_t amostra_tempo, PiscaAlerta, bip_tensao, temp;
// int JoyAX = 255, JoyAY = 255;
int JoyBX = 90, JoyBY = 90;
boolean SetaD = false, SetaE = false, pisca = false, Sire = false, SireR = false;
float tensao = 0;
// Variável Global para armazenar os caracteres que o arduino receber do celular via módulo bluetooth
// char DadosRecebidos;
void setup() {
Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
Dabble.begin("Jeep_Wills_01"); //set bluetooth name of your device
servo.setPeriodHertz(50);// Standard 50hz servo
servo.attach(Direcao); // Informando que o servo motor está conectado ao pino digital 9 do Arduino
pinMode(Farol, OUTPUT); // Leds - Farol
pinMode(Lant_Freio, OUTPUT); // Leds - Lanterna/Luz Freio
pinMode(Buzina, OUTPUT); // Buzzer - Buzinha
pinMode(PonteH1, OUTPUT); // Ponte H
pinMode(PonteH2, OUTPUT); // Ponte H
pinMode(LedSetDir, OUTPUT); // Leds - Seta Direita
pinMode(LedSetEsq, OUTPUT); // Leds - Seta Esquerda
ledcSetup(Pwm_Char,Pwm_Freq,Pwm_Res);
ledcAttachPin(Pwm,Pwm_Char);
tone(Buzina, 1000, 100);
delay(100);
tone(Buzina, 800, 100);
delay(100);
tone(Buzina, 600, 100);
delay(100);
tone(Buzina, 400, 100);
delay(100);
tone(Buzina, 200, 100);
delay(100);
// Displays DISTRESSED_EYES on the screen
// display.drawBitmap(0, 0, image_data_WORD_HELLOarray, 128, 64, 1);
// display.display();
}
void paraFrente(){
digitalWrite(PonteH1,HIGH);
digitalWrite(PonteH2,LOW);
ledcWrite(Pwm_Char,255);
}
void paraTras(){
digitalWrite(PonteH1,LOW);
digitalWrite(PonteH2,HIGH);
ledcWrite(Pwm_Char,255);
}
void parar(){
digitalWrite(PonteH1,LOW);
digitalWrite(PonteH2,LOW);
}
void loop() {
Dabble.processInput();
// DadosRecebidos = Serial.read(); // Variável DadosRecebidos armazena os dados recebidos da comunicação serial entre o celular e o Módulo Bluetooth
// Serial.print(DadosRecebidos);
if (GamePad.isCirclePressed())
{
Serial.print("Circulo");
paraFrente();
} else if (GamePad.isCrossPressed())
{
Serial.print("X");
paraTras();
} else {
parar();
}
if (GamePad.isLeftPressed())
{
Serial.print("Left");
JoyBX = Serial.parseInt();
}
if (GamePad.isRightPressed())
{
Serial.print("Right");
}
servo.write(JoyBX);
}