LCD 課題6 @アニメーション SW 右回転 左回転

Dependencies:   TextLCD mbed

main.cpp

Committer:
nakano_han
Date:
2016-10-11
Revision:
0:fe3171c289a6

File content as of revision 0:fe3171c289a6:

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

TextLCD lcd(D8,D10,D11,D12,D13,D14); // rs, e, d4, d5, d6, d7)  //LCD出力設定
AnalogIn sw1(A5);   //SW入力設定
AnalogIn sw2(A4);   //SW入力設定
DigitalOut out4(D4);    //LED出力設定
int main()
{
    int a = 0;      //関数aを定義
    int y = 0;
    
    lcd.locate(a,y);        //表示座標
    lcd.puts("@");          //文字表示 

    while(1)        //無限ループ
    {
        if(sw1 == 1)    //swが押されたら{}内実行
        {
            if(a <= 16 && y == 0)
            {
                a++;
                wait(0.5);
            }
            
            if(a >= 0 && y == 1)
            {
                a--;
                wait(0.5);
            }
                
            if(y == 0 && a >= 16)
            {
                a = 15;
                y = 1;
            }
            
            if(y == 1 && a < 0)
            {
                a = 0;
                y = 0;
            }
            lcd.cls();
        }
        
        if(sw2 == 1)
        {
            if(a <= 16 && y == 0)
            {
                a--;
                wait(0.5);
            }
            
            if(a >= 0 && y == 1)
            {
                a++;
                wait(0.5);
            }
                
            if(y == 0 && a < 0)
            {
                
                a = 0;
                y = 1;
            }
            if(y == 1 && a >= 16)
            {
                a = 15;
                y = 0;
            }
            lcd.cls();
        }
        lcd.locate(a,y);        //表示座標
        lcd.puts("@");          //文字表示 
    }        
}