#include <WiFi.h>
#include <esp_now.h>
const int PIN_EIXO_X = 34;
const int PIN_EIXO_Y = 35;
const int PIN_BOTAO = 23;
uint8_t macDoCarrinho[] = {0x24, 0x6F, 0x28, 0xAA, 0xBB, 0xCC};
struct PacoteControle {
int16_t eixoX;
int16_t eixoY;
bool botaoPressionado;
};
void loop() {
PacoteControle pacote;
pacote.eixoX = map(analogRead(PIN_EIXO_X), 0, 4095, -100, 100);
pacote.eixoY = map(analogRead(PIN_EIXO_Y), 0, 4095, -100, 100);
pacote.botaoPressionado = digitalRead(PIN_BOTAO) == LOW;
esp_now_send(macDoCarrinho, (uint8_t *)&pacote, sizeof(pacote));
delay(80);
}
#include <WiFi.h>
#include <esp_now.h>
struct PacoteControle {
int16_t eixoX;
int16_t eixoY;
bool botaoPressionado;
};
PacoteControle ultimoComando = {0, 0, false};
void moverCarrinho(int eixoX, int eixoY) {
int velocidadeBase = map(abs(eixoY), 0, 100, 0, 255);
int ajusteCurva = map(eixoX, -100, 100, -120, 120);
int esquerda = velocidadeBase - ajusteCurva;
int direita = velocidadeBase + ajusteCurva;
if (eixoY < 0) {
esquerda *= -1;
direita *= -1;
}
controlarMotor(MOTOR_ESQ_IN1, MOTOR_ESQ_IN2, MOTOR_ESQ_PWM, esquerda);
controlarMotor(MOTOR_DIR_IN1, MOTOR_DIR_IN2, MOTOR_DIR_PWM, direita);
}