ES ordening

This commit is contained in:
Rens Pastoor
2025-05-27 23:20:05 +02:00
parent d9244f1ae3
commit 39269a71a7
49 changed files with 1952 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
#include <Wire.h>
#include <Arduino.h>
uint8_t count = 0;
void setup() {
Wire.begin(); // Master
Serial.begin(9600);
}
void loop() {
// Send count to slave
Wire.beginTransmission(0x42);
Wire.write(count);
Wire.endTransmission();
Serial.print("Sent: ");
Serial.println(count);
// Request response from slave
Wire.requestFrom(0x42, 1);
if (Wire.available()) {
uint8_t response = Wire.read();
Serial.print("Received: ");
Serial.println(response);
}
count++;
}

View File

@@ -0,0 +1,29 @@
#include <Arduino.h>
#include <Wire.h>
volatile uint8_t receivedValue = 0;
void setup() {
Wire.begin(0x42);
Wire.onReceive(receiveEvent);
Wire.onRequest(requestEvent);
Serial.begin(9600);
}
void loop() {
}
void receiveEvent(int howMany) {
if (howMany > 0) {
receivedValue = Wire.read();
Serial.print("Received from master: ");
Serial.println(receivedValue);
}
}
void requestEvent() {
uint8_t reply = (receivedValue > 100) ? 2 : 4;
Wire.write(reply);
Serial.print("Sent to master: ");
Serial.println(reply);
}