LCD 課題2 @アニメーション 周回数カウント

Dependencies:   TextLCD mbed

main.cpp

Committer:
nakano_han
Date:
2016-10-06
Revision:
1:8c27d4a7a04d
Parent:
0:5912664cbcc5

File content as of revision 1:8c27d4a7a04d:

#include "mbed.h"
#include "TextLCD.h"

TextLCD lcd(D8,D10,D11,D12,D13,D14); // rs, e, d4, d5, d6, d7)      //LCD出力設定
int main(){
    int cnt = 0;        //関数cntを定義
    while(1)        //無限ループ
    {
        lcd.cls();      //LCD表示初期化
        int a = 0;      //関数aを定義

        for(a = 0; a <= 13; a++)    //aの初期値0,aが13以下の間繰り返す,1周ごとに1足す
        {
            lcd.locate(a,0);        //表示座標
            lcd.puts("@");          //文字表示
            lcd.locate(14,1);       //表示座標
            lcd.putc((cnt/10) % 10 + '0');      //cntの10の位を表示
            lcd.putc((cnt/1)  % 10 + '0');      //cntの1の位を表示
            wait(0.2);      //0.2秒待つ

            lcd.cls();      //LCD表示初期化    
        }
        for(a = 13; a >= 0; a--)    //aの初期値13,aが0以上の間繰り返す,1周ごとに1引く
        {
            lcd.locate(a,1);        //表示座標
            lcd.puts("@");          //文字表示
            lcd.locate(14,1);       //表示座標
            lcd.putc((cnt/10) % 10 + '0');      //cntの10の位を表示
            lcd.putc((cnt/1)  % 10 + '0');      //cntの1の位を表示
            wait(0.2);      //0.2秒待つ
            
            lcd.cls();      //LCD表示初期化
        }
        cnt++;      //cntに1足す
        if(cnt==100)        //cntが100になったら{}内実行
        {
            cnt = 0;        //cntを初期化
        }
        
    }
}