source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/hardware/arduino/avr/libraries/Wire/examples/slave_receiver/slave_receiver.ino @ 46

Last change on this file since 46 was 46, checked in by jrpelegrina, 4 years ago

First release to Xenial

File size: 977 bytes
Line 
1// Wire Slave Receiver
2// by Nicholas Zambetti <http://www.zambetti.com>
3
4// Demonstrates use of the Wire library
5// Receives data as an I2C/TWI slave device
6// Refer to the "Wire Master Writer" example for use with this
7
8// Created 29 March 2006
9
10// This example code is in the public domain.
11
12
13#include <Wire.h>
14
15void setup() {
16  Wire.begin(8);                // join i2c bus with address #8
17  Wire.onReceive(receiveEvent); // register event
18  Serial.begin(9600);           // start serial for output
19}
20
21void loop() {
22  delay(100);
23}
24
25// function that executes whenever data is received from master
26// this function is registered as an event, see setup()
27void receiveEvent(int howMany) {
28  while (1 < Wire.available()) { // loop through all but the last
29    char c = Wire.read(); // receive byte as a character
30    Serial.print(c);         // print the character
31  }
32  int x = Wire.read();    // receive byte as an integer
33  Serial.println(x);         // print the integer
34}
Note: See TracBrowser for help on using the repository browser.