In this week we will design, build, and connect wired or wireless node(s) with network or bus addresses.
#include void setup() { Wire.begin(1); // Begin using Wire in slave mode, where it will respond at "1" when other I2C masters chips initiate communication. Wire.onReceive(receiveEvent); // Causes "receiveEvent" to be called when a master device sends data. This only works in slave mode. Serial.begin(9600); //start serial communication pinMode(13,OUTPUT); //LED pin on arduino } byte x = 0; void loop () { delay(100); } //function that executes whenver data is received from master void receiveEvent(int howMany){ //howMany contains the amount of bytes of the received data while(Wire.available()){ char c = Wire.read(); Serial.println(c); if (c == 's') {digitalWrite (13,HIGH);} //Turn on LED else if (c == 'x') {digitalWrite (13,LOW);} //Turn off LED }}
#include void setup() { Wire.begin(); // Begin using Wire in master mode, it will initiate and control data transfers. } void loop () { Wire.beginTransmission(1); //Start a new transmission to a device at "address number 1" Wire.write('s'); //send data: letter s Wire.endTransmission(); //ends the transmission and causes all buffered data to be sent. delay (500); Wire.beginTransmission(1); //Start a new transmission to a device at "address number 1" Wire.write('x'); //send data: letter x Wire.endTransmission(); //ends the transmission and causes all buffered data to be sent. delay (500); }