美文网首页科技创新
LCD 1602 代码编写

LCD 1602 代码编写

作者: Mr洋1 | 来源:发表于2019-10-06 20:41 被阅读0次

    附加LCD1602:

    LCD 1602的连接与使用
    mixly中的简化代码:

    • 电路连接图
    1 table
    • 实物图


      实物图
      程序图
    #include <LiquidCrystal.h>
    
    LiquidCrystal mylcd(12,11,5,4,3,2);
    
    void setup(){
      mylcd.begin(16,2);
      mylcd.display();
    }
    
    void loop(){
      mylcd.setCursor(0, 0);
      mylcd.print("HELLO");
      mylcd.setCursor(0, 1);
      mylcd.print("WORLD");
    
    }
    
    #include <LiquidCrystal.h> //Load Liquid Crystal Library
    
    LiquidCrystal  LCD(10,  9,  5,  4,  3,  2);  //Create Liquid Crystal Object called LCD
    
    int  myCounter=0;  //declare your variable myCounter and set to 0
    
    void  setup()  {
    
    LCD.begin(16,2);  //Tell Arduino to start your 16 column 2 row LCD
    
    LCD.setCursor(0,0);  //Set LCD cursor to upper left corner, column 0, row 0
    
    LCD.print("My Timer:");  //Print Message on First Row
    
    }
    
    void  loop()  {
    
      for  (myCounter=1;  myCounter<=10;  myCounter=myCounter+1)  {
    
     LCD.setCursor(0,1);  //Go to 1st column(column 0) and 2nd row(row 1)
    
     LCD.print(myCounter);
    
     LCD.print(" Seconds");  
    
     delay(1000);
    
        }
    
      for  (myCounter=10;myCounter>=0;myCounter=myCounter-1)  {
    
     LCD.setCursor(0,1);  //Go to 1st column(column 0) and 2nd row(row 1)
    
     LCD.print(myCounter);
    
     LCD.print(" Seconds");  
    
     delay(1000);
    
      }  
    
    }
    
     
    
    

    scoot 溜走 scoot back
    vexing problem 烦恼问题

    #include <LiquidCrystal.h> //Load Liquid Crystal Library
    LiquidCrystal LCD(10, 9, 5, 4, 3, 2);  //Create Liquid Crystal Object called LCD
    int myCounter=0;  //declare your variable myCounter and set to 0
    
    void setup() {
     
    LCD.begin(16,2); //Tell Arduino to start your 16 column 2 row LCD
    LCD.setCursor(0,0);  //Set LCD cursor to upper left corner, column 0, row 0
    LCD.print("My Timer:");  //Print Message on First Row
    }
    
    void loop() {
      for (myCounter=1; myCounter<=10; myCounter=myCounter+1) {
         LCD.setCursor(0,1); //Go to 1st column(column 0) and 2nd row(row 1)
         LCD.print("                "); //Print blanks to clear the row
         LCD.setCursor(0,1); //Go to 1st column(column 0) and 2nd row(row 1)
         LCD.print(myCounter); 
         LCD.print(" Seconds");  
         delay(1000);
        }
    
      for (myCounter=10;myCounter>=0;myCounter=myCounter-1) {
         LCD.setCursor(0,1); //Go to 1st column(column 0) and 2nd row(row 1)
         LCD.print("                "); //Print blanks to clear the row
         LCD.setCursor(0,1); //Go to 1st column(column 0) and 2nd row(row 1)
         LCD.print(myCounter); 
         LCD.print(" Seconds");  
         delay(1000);
      }
    
    • 连接图2


      连接图
    正极 程序 colo
    https://detail.tmall.com/item.htm?spm=a230r.1.14.6.99da4c6aPUWRL5&id=530432143336&cm_id=140105335569ed55e27b&abbucket=10 trigger
    int trigPin=13; //Sensor Trip pin connected to Arduino pin 13
    int echoPin=11;  //Sensor Echo pin connected to Arduino pin 11
    float pingTime;
    float speedOfSound;
    int targetDistance=6; //Distance to Target in inches
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
      pinMode(trigPin, OUTPUT);
      pinMode(echoPin, INPUT);
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly: 
      
      digitalWrite(trigPin, LOW); //Set trigger pin low
      delayMicroseconds(2000); //Let signal settle
      digitalWrite(trigPin, HIGH); //Set trigPin high
      delayMicroseconds(10); //Delay in high state
      digitalWrite(trigPin, LOW); //ping has now been sent
      
      pingTime = pulseIn(echoPin, HIGH);  //pingTime is presented in microceconds
     
      speedOfSound = (targetDistance*2)/pingTime*(1000000)*3600/63360;        //converts to miles per hour
      Serial.print("The Speed of Sound is: ");
      Serial.print(speedOfSound);
      Serial.println(" miles per hour");
      delay(1000);
      
    }
    

    项目---》加载库---》管理库

    load lib

    相关文章

      网友评论

        本文标题:LCD 1602 代码编写

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