#include <LiquidCrystal_I2C.h> //アドレス0x27 16文字2行の液晶 LiquidCrystal_I2C lcd(0x27, 16, 2); void wait_microsec(long wait) { long start = micros(); while (( micros() - start) < wait); } void setup() { pinMode( 3, INPUT); pinMode( 2, OUTPUT); lcd.init(); lcd.backlight(); } void loop(){ digitalWrite( 2, HIGH); wait_microsec( 11); digitalWrite( 2, LOW); unsigned long range = pulseIn( 3, HIGH ,1000000); if ( range ) { range = ( ( range * 340) / 2) / 1000; lcd.setCursor( 0 , 0); lcd.print( range / 10 , DEC); lcd.print( "."); lcd.print( range - ( ( range / 10) * 10) , DEC); lcd.print( " cm "); } delay( 200); }