更新一下I2C的1602事例:
#include<LiquidCrystal_I2C.h>
#include <Wire.h>
//LiquidCrystal_I2C Lcd(0x27,16,02);
LiquidCrystal_I2C lcd(0x27,20,4);
//LiquidCrystal lcd(12,11,5,4,3,2);
int Tfa = 8;
int Ehk = 9;
float juli;
byte armsDown[8] = {
0b00100,
0b01010,
0b00100,
0b00100,
0b01110,
0b10101,
0b00100,
0b01010
};
byte armsUp[8] = {
0b00100,
0b01010,
0b00100,
0b10101,
0b01110,
0b00100,
0b00100,
0b01010
};
void setup(){
Serial.begin(9600);
pinMode(Tfa,OUTPUT);
pinMode(Ehk,INPUT);
// lcd.begin(16,2);
lcd.init();
lcd.backlight();
lcd.print("lcd already ok");
/* lcd.createChar(1, armsDown);
// create a new character
lcd.createChar(2, armsUp);*/
delay(2000);
lcd.clear();
}
void loop()
{
digitalWrite(Tfa,LOW);
delayMicroseconds(2);
digitalWrite(Tfa,HIGH);
delayMicroseconds(10);
juli = pulseIn(Ehk,HIGH)/58.30;
Serial.print(juli);
Serial.print("cm");
Serial.println();
/*switch(chk){
case DHTLIB_OK:
Serial.println("ok");
break;
//case DHTLIB_ERROR_TIMEOUT:
Serial.println("ERROR_TIMEOUT");
break;
//case DHTLIB_ERROR_CHECKSUM:
Serial.println("CHECKSUM ERROR");
break;
default:
Serial.println("ok ko");
break;
}*/
lcd.setCursor(0,0);
lcd.print(juli);
lcd.print("cm");
//delay(3000);//wating 3s,clear lcd.
if(juli>=2000){
delay(50);}
else{
delay(3000);//wating 3s,clear lcd.
}
//fang zhi wupan
//delay(3000);//wating 3s,clear lcd.
lcd.setCursor(0,0);
lcd.clear();
lcd.setCursor(4, 1);
// draw the little man, arms down:
lcd.write(2);
delay(300);
lcd.setCursor(4, 1);
// draw him arms up:
lcd.write(1);
delay(300);
}
|