Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 4223|回復: 1
打印 上一主題 下一主題

LCD 計數器問題

[複製鏈接]
跳轉到指定樓層
1#
發表於 2014-12-30 11:10:48 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本帖最後由 vincent8034 於 2014-12-30 11:13 編輯

我是arduino新手
我設計一個用按鈕來計數的程式,數字是從0>9,9以上就跳回0但我想在加入一個清除的按鈕,就是我在途中(0到9之間)按一個鈕直接跳回0
請問改如何改
以下是我的程式:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int pushButton = 7;
int x = 0;


LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()
{
        pinMode(pushButton, INPUT);


        lcd.begin();


        lcd.backlight();
        lcd.setCursor(0,0);


}

void loop()
{

  int i;
  char a1,a2;
  i = digitalRead(pushButton);
  if(i == HIGH)
  {
    x++;
    a1=x%10;
    a2=(x/10)%10;
    lcd.setCursor(1,0);
    lcd.write(a1+'0');
    lcd.setCursor(0,0);
    lcd.write(a2+'0');

    if (x>=10) x=0;


  }
  Serial.print(x);
  delay(100);
}
2#
發表於 2014-12-30 13:52:52 | 只看該作者
回復 1# vincent8034


   

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int pushButton = 7;
int x = 0;


LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()
{
        pinMode(pushButton, INPUT);


        lcd.begin();


        lcd.backlight();
        lcd.setCursor(0,0);


}

void loop()
{

  int i;
  char a1,a2;
  i = digitalRead(pushButton);
  if(i == HIGH)
  {
    x++;
    a1=x%10;
    a2=(x/10)%10;
    lcd.setCursor(1,0);
    lcd.write(a1+'0');
    lcd.setCursor(0,0);
    lcd.write(a2+'0');

    if (x==10){
   
    x=0;
  
    }
  Serial.print(x);
  delay(100);
}

看修改成紅色那3行看看.....
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-9-30 17:24 , Processed in 0.157280 second(s), 8 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表