LCD编程与Arduino的 [英] LCD Programming with Arduino

查看:262
本文介绍了LCD编程与Arduino的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的LCD,显示电压=(sensorValue),但现在唯一的办法,我可以让程序对价确认为我打开电位器,如果我把它放在一个循环。但是,当我把它放在一个循环,整个画面被充满了1S,2S,3S,4S,5S或者不同的地方电位器设定。

如果我没有它在一个循环中那么无论设置电位器上是会弹出在屏幕上,如果电位器开启也不会改变。

我怎样才能把一个循环的结果的循环外,所以我可以有(电压= sensoreValue)?

下面是我的程序:

 的#include< Wire.h>
#包括LT&;&LiquidCrystal_I2C.h GT;LiquidCrystal_I2C LCD(0x27,16,2);无效设置()
{
    lcd.init();
    lcd.backlight();
    INT sensorPin = A0;
    INT sensorValue = 0;
    sensorValue = 0.004882812 * analogRead(sensorPin)+ 1;
    lcd.print(电压=);
}无效循环()
{
    INT sensorPin = A0;
    INT sensorValue = 0;
    sensorValue = 0.004882812 * analogRead(sensorPin)+ 1;
    lcd.print(sensorValue);
}


解决方案

您要求它打印阅读和它做 - !它的打印每个读

我怀疑你要么只想打印如果价值变动

  INT sensorValue = 0;
INT prevValue = 0;无效循环()
{
    sensorValue = 0.004882812 * analogRead(sensorPin)+ 1;
    如果(sensorValue!= prevValue){
       lcd.print(sensorValue);
       prevValue == sensorValue;
    }
}

另外,您可以打印'N'退格,因此新值将被打印在旧的顶部,如果你的显示器lcd.print支持

I would like my LCD to display "Voltage=(sensorValue)" but right now the only way I can get the program to recognize the value as I turn the potentiometer is if I put it in a loop. But when I put it in a loop the whole screen gets filled with 1s, 2s, 3s, 4s, or 5s depending on where the potentiometer is set.

If I don't have it in a loop then whatever setting the potentiometer is on is what will pop on the screen and will not change if potentiometer is turned.

How can I put the results of a loop outside of a loop so I can have "(Voltage=sensoreValue)"?

Here's my program:

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);  

void setup()
{
    lcd.init();                      
    lcd.backlight();
    int sensorPin = A0;
    int sensorValue = 0;
    sensorValue = 0.004882812 * analogRead(sensorPin) + 1;
    lcd.print("Voltage=");
}

void loop()
{
    int sensorPin = A0;
    int sensorValue = 0;
    sensorValue = 0.004882812 * analogRead(sensorPin) + 1;
    lcd.print(sensorValue);
}

解决方案

You asked it to print the reading and it is doing - it's printing each reading!

I suspect you either want it to only print if the value changes

int sensorValue = 0;
int prevValue = 0;

void loop()
{    
    sensorValue = 0.004882812 * analogRead(sensorPin) + 1;
    if (sensorValue != prevValue) {
       lcd.print(sensorValue);
       prevValue == sensorValue;
    }
}

Alternatively you could print 'n' backspaces so the new value is printed over the top of the old one, if your display lcd.print supports that

这篇关于LCD编程与Arduino的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆