Robofun 機器人論壇

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

資料型態轉換的問題

[複製鏈接]
跳轉到指定樓層
1#
發表於 2015-2-11 16:36:29 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
先上傳程式給各位看一下:

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


LiquidCrystal_I2C lcd(0x27, 16, 2);


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

        lcd.begin();
        lcd.backlight();
        lcd.setCursor(0,0);
       
char s[] = {'b1','b2'};
int t = atoi(s);


}


void loop()
{
  char a1,a2,b1,b2;
  b1='8';
  b2='1';
  lcd.setCursor(1,1);
  lcd.write(b1);
  lcd.setCursor(0,1);
  lcd.write(b2);
  int i;
  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>=20) x=0;
  }
if( x >= t)
{
   digitalWrite(ledpin, HIGH);
}
else
{
   digitalWrite(ledpin, LOW);
}
}






程式目的:
按下 pushButton LCD會顯示+1,到>=20會歸零,但我想加入一個指定數值"18",當按鈕++到指定數值時led會亮燈


但led並不會亮,我想事資料型態轉換的問題,請問這要如何改??
謝謝~~~
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-6-10 18:38 , Processed in 0.260272 second(s), 8 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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