Master Swordの吹奏楽部展示時用のプログラムです

Dependencies:   TextLCD mbed

Fork of MIYABI_Drive by Nin_PTD_Mecha

main.cpp

Committer:
iwaki
Date:
2017-07-27
Revision:
2:41795d8bc7cb
Parent:
0:fb6bbc10ffa0
Child:
3:3707e3934185

File content as of revision 2:41795d8bc7cb:

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

PwmOut led1(LED1);
PwmOut led2(LED2);
PwmOut led3(LED3);
PwmOut led4(LED4);

PwmOut moter1(p21);
PwmOut moter2(p22);
DigitalIn sw1(p23);

TextLCD lcd(p24, p26, p27, p28, p29, p30);      // rs, e, d0-d3

int main() {
    
    int i;
    int s;
    int n;
    
    i = 0;
    s = 0;
    n = 100;
    
    sw1.mode( PullUp );
    moter1 = 0.0;
    moter2 = 0.0;
    
    //離れての表示と、動作待ちの5秒待機
    lcd.cls();
    lcd.locate(0,0);
    lcd.printf("Ready to start");
    lcd.locate(0,1);
    lcd.printf("Don't touch me");
    wait(5);
    
    //モータ出力ON
    moter1 = 0.1;
    moter2 = 0.1;
    
    while(1) {
        
        //クリック回数のカウント
        //チャタリング防止のためタイマ有り
        //一度OFFになったことを検知するステータスフラグあり
        if(sw1 == 0 and s == 0) {
            s = 1;
            i++;
            wait(0.0001);
        }
        else if(sw1 == 1) {
            s = 0;
        }   
        
        //LCDへの回数の記載
        lcd.cls();
        lcd.locate(0,0);
        lcd.printf("%d",i);
        
        //テスト中か、終了したかのLCDへの記載
        if( n > i ) {
            lcd.locate(0,1);
            lcd.printf("testing");
        }
        else {
            lcd.locate(0,1);
            lcd.printf("End");
            
            moter1 = 0;
            moter2 = 0;
        }
        
        //LCDへの記載を安定させるための待機
        wait(0.05);
    }
}