如何从Arduino中清除LCD?

时间:2014-01-14 18:55:39

标签: arduino lcd

我正在使用串行通信将数据显示到我的4x20液晶显示屏上。当我填满所有线路时,我需要清除它。我在网上搜索,发现了类似的内容:

Serial.write(27); // ESC command
Serial.print("[2J"); // clear screen command
Serial.write(27);
Serial.print("[H"); // cursor to home command

但它不起作用。我还找到了像Serial.println();这样的解决方案,但该解决方案(他们称之为欺骗)只能在串行监视器上运行。那么是否有任何可能的解决方案来清除显示器或从LCD中删除单个字符?

4 个答案:

答案 0 :(得分:1)

你试过lcd.clear()吗?它在文档here中说该命令执行以下操作:

  

清除LCD屏幕并将光标定位在左上角   角。

显然,您需要lcd变量(称为LiquidCrystal对象)才能使用此方法。了解如何创建here以及下面的基本实现。也许您可以在lcd.print("hello, world!");之后添加时间延迟,然后添加lcd.clear();(就像基本的概念验证一样。)

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

void setup()
{
  lcd.begin(16,1);
  lcd.print("hello, world!");
}

void loop() {}

查看完整的LiquidCrystal reference了解其所有方法和其他示例。

答案 1 :(得分:1)

我找到了解决问题的快速解决方案

for (int i=0; i < 80; i++) { Serial.write(8); // print 80 times forward (BS) }

如果你有更大的显示,只需增加循环的值。正如我在串行监视器中观察到的那样,光标向前推,直到线条清晰(基于你的循环)。但这不允许您删除显示中的单个字符。

答案 2 :(得分:0)

您是否尝试按此Arduino Playground 0 SerialLCD发布内容详细发送12(0x0C)

void setup()
{
  Serial.begin(19200); // era beginSerial

void loop()
{ 
  //backlightOn(0);  // turn the backlight on all the time

  clearLCD();
  Serial.write(" Hello");  // print text to the current cursor position
  newLine();              // start a new line
  Serial.write("Arduino");
  delay(1000);
}

//  LCD  FUNCTIONS-- keep the ones you need. 

// clear the LCD
void clearLCD(){
  Serial.write(12);
}


// start a new line
void newLine() { 
  Serial.write(10); 
}

见上面其他命令的链接。

答案 3 :(得分:0)

我发现最好的方法是简单地将以下行添加到草图中:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim AffectedRange As Range
    Set AffectedRange = Intersect(Target, Target.Parent.Range("C6, C9:G9"))

    Application.EnableEvents = False 'pervent triggering another change event
    On Error GoTo ERR_HANDLING

    If Not AffectedRange Is Nothing Then
        Dim Cel As Range
        For Each Cel In AffectedRange.Cells
            Cel.Value = LCase$(Cel.Value)
        Next Cel
    End If

    On Error GoTo 0

    'no Exit Sub here!
ERR_HANDLING:
    Application.EnableEvents = True 

    If Err.Number <> 0 Then
        Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
    End If
End Sub

这将使LCD显示屏清晰可见。