Skip to content

Instantly share code, notes, and snippets.

@Corinrypkema
Last active December 4, 2015 04:04
Show Gist options
  • Save Corinrypkema/8300211b822c4e3567a5 to your computer and use it in GitHub Desktop.
Save Corinrypkema/8300211b822c4e3567a5 to your computer and use it in GitHub Desktop.
I2C example from arduino with modifications for LightBlue(TM) testing
#include <Wire.h>
byte val = 0;
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop() {
delay(1000);
val ^= 1 << 0;
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
Wire.write(val); // respond with message of 1 bytes
// as expected by master
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment