/* This sketch runs on an Arduino connected to an ATtiny85 running w13_tiny_slave.ino The data received is from a HC-SR04 sensor */ #include #include LiquidCrystal_I2C lcd(0x27,16,2); byte distance; // Where the Distance is stored (8 bit unsigned) void setup() { Wire.begin(); Serial.begin(9600); // Serial.println("Setup"); /* LCD 16x2 */ lcd.init(); lcd.backlight(); lcd.clear(); } void loop() { Wire.requestFrom(7, 1); // The TinyWire library only allows for one byte to be requested at a time while (Wire.available() == 0) ; // Wait until there is data in the I2C buffer distance = Wire.read(); // Read the first (and hopefully only) byte in the I2C buffer // Serial.println(distance); lcd.setCursor(0,0); lcd.print(" "); // erase line lcd.setCursor(0,0); lcd.print("Distance:"); lcd.print(distance,1); lcd.print("cm"); delay(300); // The sensor only updates every 30 ms. Asking for new data quicker than that is useless }