美文网首页科技创新
Arduino LCD 1602 作业

Arduino LCD 1602 作业

作者: mouse0531 | 来源:发表于2019-11-30 15:14 被阅读0次

    这是我们这次的作业:LCD 1602 作业。

    任务
    用LCD 1602显示超声波传感器和温湿度传感器的数据

    任务(1)

    这是它的接线图: 接线图(1) 这是它的程序图: 程序图(2)
    #include <LiquidCrystal.h>
    
    LiquidCrystal mylcd(12,11,6,5,4,3);
    float checkdistance_12_13() {
      digitalWrite(12, LOW);
      delayMicroseconds(2);
      digitalWrite(12, HIGH);
      delayMicroseconds(10);
      digitalWrite(12, LOW);
      float distance = pulseIn(13, HIGH) / 58.00;
      delay(10);
      return distance;
    }
    
    void setup(){
      mylcd.begin(16,2);
      mylcd.display();
      pinMode(12, OUTPUT);
      pinMode(13, INPUT);
    }
    
    void loop(){
      mylcd.setCursor(1-1, 1-1);
      mylcd.print(checkdistance_12_13());
    
    }
    

    任务(2)

    这是它的接线图: 接线图(2) 这是它的程序图: 程序图(2)
    #include <LiquidCrystal.h>
    #include <dht.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    
    LiquidCrystal mylcd(11,10,6,5,4,3);
    dht myDHT_12;
    int dht_12_gettemperature() {
      int chk = myDHT_12.read11(12);
      int value = myDHT_12.temperature;
      return value;
    }
    
    OneWire oneWire_13(13);
    DallasTemperature sensors_13(&oneWire_13);
    DeviceAddress insideThermometer;
    float ds18b20_13_getTemp(int w) {
      sensors_13.requestTemperatures();
      if(w==0) {return sensors_13.getTempC(insideThermometer);}
      else {return sensors_13.getTempF(insideThermometer);}
    }
    
    void setup(){
      mylcd.begin(16,2);
      mylcd.display();
      sensors_13.getAddress(insideThermometer, 0);
      sensors_13.setResolution(insideThermometer, 9);
    }
    
    void loop(){
      mylcd.setCursor(0, 0);
      mylcd.print(dht_12_gettemperature());
      mylcd.setCursor(0, 1);
      mylcd.print(ds18b20_13_getTemp(0));
    
    }
    

    谢谢观看!

    相关文章

      网友评论

        本文标题:Arduino LCD 1602 作业

        本文链接:https://www.haomeiwen.com/subject/lkjowctx.html