[2:41 PM, 5/30/2024] Jeff Padilla: // MAESTRO
#include <Wire.h>
#define SLAVE_ADDRESS 0x04
#define POT_PIN 34
void setup() {
Wire.begin(); // Iniciar I2C como maestro
Serial.begin(115200);
}
void loop() {
int potValue = analogRead(POT_PIN); // Leer valor del potenciómetro
int mappedValue = map(potValue, 0, 4095, 0, 255); // Mapear el valor a rango de 0-255
Wire.beginTransmission(SLAVE_ADDRESS);
Wire.write(mappedValue); // Enviar valor mapeado al esclavo
Wire.endTransmission();
Serial.print("Potentiometer Value: ");
Serial.println(mappedValue);
delay(100); // Esperar un poco antes de la próxima lectura
}
[2:41 PM, 5/30/2024] Jeff Padilla: // ESCLAVO
#include <Wire.h>
#define LED_PIN 12
void setup() {
Wire.begin(0x04); // Iniciar I2C como esclavo con dirección 0x04
Wire.onReceive(receiveEvent); // Registrar función para recibir datos
pinMode(LED_PIN, OUTPUT); // Configurar pin del LED como salida
Serial.begin(115200);
}
void loop() {
// No es necesario hacer nada aquí, ya que la recepción de datos se maneja por interrupción
}
void receiveEvent(int howMany) {
while (Wire.available()) {
int receivedValue = Wire.read(); // Leer el valor recibido
Serial.print("Received Value: ");
Serial.println(receivedValue); // Imprimir valor recibido
analogWrite(LED_PIN, receivedValue); // Ajustar intensidad del LED
}
}Loading
esp32-devkit-c-v4
esp32-devkit-c-v4
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4