arduino/I2C_SLAVE_PHOTORESISTOR/I2C_SLAVE_PHOTORESISTOR.ino

22 lines
373 B
C++

#include <Wire.h>
int lightPin = 0;
void setup()
{
Wire.begin(7); // join i2c bus with address #7
Wire.onRequest(requestEvent); // register event
Serial.begin(9600); //Begin serial communcation
}
void loop()
{
Serial.println(analogRead(lightPin));
delay(1000);
}
void requestEvent()
{
Wire.write(analogRead(lightPin)); // respond with message of 6 bytes
}