Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "TinyWireS.h" // wrapper class for I2C slave routines
- #define I2C_SLAVE_ADDR 8 // i2c slave address (8) - defined in master code
- #define LED_PIN 5 // ATtiny PB2- Pin8
- void setup(){
- pinMode(LED_PIN,OUTPUT); // for general DEBUG use
- digitalWrite(LED_PIN,HIGH); //LED turns on to sayit's alive
- delay(200);
- TinyWireS.begin(I2C_SLAVE_ADDR); // init I2C Slave mode
- }
- void loop(){
- byte byteRcvd = 0;
- if (TinyWireS.available()){ // TinyWireS.available() returns the number of bytes in the received buffer
- byteRcvd = TinyWireS.receive(); // TinyWireS.receive()returns the next byte in the received buffer??
- digitalWrite(LED_PIN,HIGH); //LED turns on
- delay(200); //LED stays on for 200ms
- digitalWrite(LED_PIN,LOW); //LED turns off
- delay(200);
- byteRcvd += 10; // add 10 to what's received
- TinyWireS.send(byteRcvd); // send it back to master
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment