Copy in slave example code from droneworkshop

This commit is contained in:
Kenwood 2021-06-27 22:57:07 -04:00
parent 3bde28770c
commit 7cc49a0406
1 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,37 @@
/*
Arduino Slave for Raspberry Pi Master
i2c_slave_ard.ino
Connects to Raspberry Pi via I2C
DroneBot Workshop 2019
https://dronebotworkshop.com
*/
// Include the Wire library for I2C
#include <Wire.h>
// LED on pin 13
const int ledPin = 13;
void setup() {
// Join I2C bus as slave with address 8
Wire.begin(0x8);
// Call receiveEvent when data received
Wire.onReceive(receiveEvent);
// Setup pin 13 as output and turn LED off
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
}
// Function that executes whenever data is received from master
void receiveEvent(int howMany) {
while (Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
digitalWrite(ledPin, c);
}
}
void loop() {
delay(100);
}