在1602液晶屏上有滚动文字,同时还能听到按钮的声音。

问题描述 投票:0回答:1

我正在使用一个带有ic2模块和1602 LCD的Arduino micro.我已经写了一个在LCD上滚动字符串的函数,但我想同时监听一个按钮的按压。

这是我的滚动代码。

void ScrollingText(String(StringToScroll), int(LineToScroll))
{
  lcd.setCursor(0, LineToScroll);
  if(StringToScroll.length() <= 16)
  {
    lcd.print(StringToScroll);
  }
  else
  {
    for (int x = 0; x < StringToScroll.length()-15; x++) {
      lcd.clear();
      delay(10);
      for (int i = 0; i < 16; i++) {
        lcd.print(StringToScroll[i+x]);
      }
      if(x == 0 or x == StringToScroll.length()-16)
      {
        delay(1000);
      }
      else
      {
       delay(400); 
      }
      lcd.setCursor(0, LineToScroll);
    }
  }
}

谢谢

button arduino lcd
1个回答
0
投票

你可以在一个 中断引脚比如说。

const byte interruptPin = 2;
volatile bool buttonState = false;

void setup() {
    pinMode(interruptPin, INPUT_PULLUP);
    attachInterrupt(digitalPinToInterrupt(interruptPin), ButtonISR, CHANGE);
}

void ButtonISR() {
     // set buttonState
}

然后检查或使用 buttonState 在你的循环中。

© www.soinside.com 2019 - 2024. All rights reserved.