极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 13666|回复: 1

有关lcd1602显示实时数据的问题

[复制链接]
发表于 2018-5-18 20:51:52 | 显示全部楼层 |阅读模式
我想使用HX711采集压力数据,并且实时显示在lcd1602显示屏上,但是实验的结果是显示屏毫无反应。。。麻烦各位大神看下我的程序,是不是程序出错了啊

const int led=9;
const int button=13;
bool currentbutton=LOW;
bool lastbutton=LOW;
bool buttonstate=false;

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

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

void setup()
{
  pinMode(led,OUTPUT);
  pinMode(button,INPUT);   
  lcd.begin(16,2);
  Serial.begin(9600);
}

bool xiaodou(bool last)
{
  bool current=digitalRead(button);
  if(current!=last)
  {
    delay(5);
    current=digitalRead(button);
  }
  return current;
}

void loop()
{
  currentbutton=xiaodou(lastbutton);
  if(lastbutton==LOW&&currentbutton==HIGH)
  {
      buttonstate=!buttonstate;     
   }
   lastbutton = currentbutton;
   digitalWrite(led,buttonstate);
   double sum1 = 0;
   
   if(digitalRead(led) == HIGH)
   {  
      for (int i = 0; i < 10; i++)
      {
         sum1 += hx.bias_read();
       }
       Serial.print("Force:");
       Serial.print(sum1/10);
       Serial.println("Kg");
      
      if(Serial.available())
      {
        delay(1000);
        lcd.clear();
        while(Serial.available()>0)
        {
            lcd.write(Serial.read());
         }
      }
   }  
}
回复

使用道具 举报

发表于 2018-5-19 14:34:40 | 显示全部楼层
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-20 22:13 , Processed in 0.051927 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表