Advertisement
alphalem

Rex to Arduino

Jan 9th, 2014
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. #include <Wire.h>
  2. const int sensorPin = 7;
  3. int sensorValue = 0;
  4. void setup () {
  5.   Wire.begin(4);
  6.   Wire.onRequest(requestEvent);
  7. }
  8. void loop() {
  9.   delay(500);
  10.   sensorValue = analogRead(sensorPin);
  11. }
  12. void requestEvent() {
  13.   uint8_t data[1];
  14.   data[0] = (uint8_t)sensorValue;
  15.   Wire.write(data, 2);
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement