标题: 有关Arduino lcd1602显示实时数据的问题 [打印本页]

作者: mioyo    时间: 2018-5-18 20:53
标题: 有关Arduino lcd1602显示实时数据的问题
我想使用HX711采集压力数据,并且实时显示在lcd1602显示屏上,但是实验的结果是显示屏毫无反应。。。麻烦各位大神看下我的程序,是不是程序出错了啊

  1. const int led=9;
  2. const int button=13;
  3. bool currentbutton=LOW;
  4. bool lastbutton=LOW;
  5. bool buttonstate=false;

  6. #include<LiquidCrystal.h>
  7. #include <HX711.h>

  8. LiquidCrystal lcd(12,11,5,4,3,2);
  9. HX711 hx(7, 8, 128, -0.00011890216);

  10. void setup()
  11. {
  12.   pinMode(led,OUTPUT);
  13.   pinMode(button,INPUT);   
  14.   lcd.begin(16,2);
  15.   Serial.begin(9600);
  16. }

  17. bool xiaodou(bool last)
  18. {
  19.   bool current=digitalRead(button);
  20.   if(current!=last)
  21.   {
  22.     delay(5);
  23.     current=digitalRead(button);
  24.   }
  25.   return current;
  26. }

  27. void loop()
  28. {
  29.   currentbutton=xiaodou(lastbutton);
  30.   if(lastbutton==LOW&¤tbutton==HIGH)
  31.   {
  32.       buttonstate=!buttonstate;     
  33.    }
  34.    lastbutton = currentbutton;
  35.    digitalWrite(led,buttonstate);
  36.    double sum1 = 0;
  37.    
  38.    if(digitalRead(led) == HIGH)
  39.    {  
  40.       for (int i = 0; i < 10; i++)
  41.       {
  42.          sum1 += hx.bias_read();
  43.        }
  44.        Serial.print("Force:");
  45.        Serial.print(sum1/10);
  46.        Serial.println("Kg");
  47.       
  48.       if(Serial.available())
  49.       {
  50.         delay(1000);
  51.         lcd.clear();
  52.         while(Serial.available()>0)
  53.         {
  54.             lcd.write(Serial.read());
  55.          }
  56.       }
  57.    }  
  58. }
复制代码



作者: devcang    时间: 2018-5-19 10:01
没有这样的实物,测试不了的。。。。。。不是有串口吗,连接串口去逐行 调试调试




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1