能正确工作的部分代码,只是偷懒用pin6当作VCC pin7当作GND,如果把pinMode写前面就能正常给LCD2004供电;
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27,20,4);
- unsigned long randNumber;
- int a,b,c,d;
- void setup() {
- pinMode(6,OUTPUT); //vcc
- pinMode(7,OUTPUT); //gnd
- digitalWrite(6,HIGH);
- digitalWrite(7,LOW);
- lcd.init();
- lcd.backlight();
- randomSeed(analogRead(A0));
- }
复制代码 如果把pinMode写后面,LCD2004不工作,万用表测试也没有电压,例如下面的代码
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27,20,4);
- unsigned long randNumber;
- int a,b,c,d;
- void setup() {
- lcd.init();
- lcd.backlight();
- randomSeed(analogRead(A0));
- pinMode(6,OUTPUT); //vcc
- pinMode(7,OUTPUT); //gnd
- digitalWrite(6,HIGH);
- digitalWrite(7,LOW);
- }
复制代码 找了半天资料没弄清楚原因,为啥要把pinMode 写前面才能正常工作呢?向老师们求教!!
|