エレキジャックweb mbed入門 mbed RMCS鉄道模型自動制御システム 課題10です。単線ですが、ポイントを一つ設置して2列車を交互運転できるレイアウトです3アクティブ光センサ、1ポイントを設置しています。コンパクトに小型アルミトランクに組み込みました。
Diff: main.cpp
- Revision:
- 0:f3675b6d19ef
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Feb 19 07:54:27 2012 +0000 @@ -0,0 +1,180 @@ +// mRMCS10 Active sensor +// Trunk rayout tansen oufuku +// mbed RailModelContorolSystem + +#include "mbed.h" +#include "TextLCD0420.h" + +#define ON 1 +#define OFF 0 +#define XON 0 +#define XOFF 1 + +DigitalOut mled1(LED1); +DigitalOut mled2(LED2); +DigitalOut mled3(LED3); +DigitalOut mled4(LED4); +AnalogIn vr1_adc(p15); +AnalogIn vr2_adc(p16); +DigitalIn sens1(p17); +DigitalIn sens2(p18); +DigitalIn sens3(p19); +PwmOut r1_pwm(p22); +PwmOut r2_pwm(p23); +DigitalOut po10(p5); +DigitalOut po11(p6); +DigitalOut po20(p7); +DigitalOut po21(p8); +DigitalIn Asens1(p9); +DigitalIn Asens2(p10); +DigitalIn Asens3(p11); + +TextLCD lcd(p24, p25, p26, p27, p28, p29, p30,20,4); // rs, rw, e, d0, d1, d2, d3 + +float pduty,pduty_slow; + +void notch(float duty){ + r1_pwm.write(duty); + r2_pwm.write(0); +} + +void r_notch(float duty){ + r1_pwm.write(0); + r2_pwm.write(duty); +} + +void point1(int x){ + if(x==0){ + po10=ON; + po11=OFF; + wait(0.2); + po10=OFF; + po11=OFF; + } + else if(x==1){ + po10=OFF; + po11=ON; + wait(0.2); + po10=OFF; + po11=OFF; + } +} + +int main() { + int i,count,ressha,init_sts; + float pduty; + r1_pwm.pulsewidth(0.000001);//1us=0.000001 + r1_pwm.period(0.00001);//1ms=0.001s + r2_pwm.pulsewidth(0.000001);//1us=0.000001 + r2_pwm.period(0.00001);//1ms=0.001s + + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Set Train on rail!!"); + lcd.locate(0,1); + lcd.printf("==>Sns1:XON,Sns2:XON"); + + notch(0); + init_sts=1; + ressha=0; + while(init_sts==1){ + if(Asens1==XON && Asens2==XON){ + lcd.cls(); + lcd.locate(0,0); + lcd.printf("** mbed RMCS **"); + lcd.locate(0,1); + lcd.printf("> Pse Main pwr on!"); + lcd.locate(0,1); + lcd.printf("> System start ..."); + wait(1.0); + point1(0); + wait(1.0); + point1(1); + wait(1.0); + point1(0); + wait(1.0); + init_sts=0; + } + } + + lcd.cls(); + lcd.locate(0,0); + lcd.printf("** mbed RMCS10 **"); + + while(1){ + + lcd.locate(0,3); + lcd.printf("Point1 0"); + point1(0); + + pduty=vr1_adc.read(); + r_notch(pduty); + wait(1.0); + while(Asens3==XOFF){ + pduty=vr1_adc.read(); + r_notch(pduty); + lcd.locate(0,1); + lcd.printf("d:%3.0f%%",pduty*100); + lcd.locate(0,2); + lcd.printf("E:001 r_notch ON!"); + } + r_notch(0); + lcd.locate(0,1); + lcd.printf("d:%3.0f%%",0); + lcd.locate(0,2); + lcd.printf("E:001 Teishachu!!"); + wait(5.0); + pduty=vr1_adc.read(); + notch(pduty); + wait(1.0); + while(Asens1==XOFF){ + pduty=vr1_adc.read(); + notch(pduty); + lcd.locate(0,1); + lcd.printf("d:%3.0f%%",pduty*100); + lcd.locate(0,2); + lcd.printf("E:001 notch ON! "); + + } + notch(0); + wait(3.0); + + lcd.locate(0,3); + lcd.printf("Point1 1"); + + point1(1); + wait(1.0); + pduty=vr2_adc.read(); + r_notch(pduty); + wait(1.0); + while(Asens3==XOFF){ + pduty=vr2_adc.read(); + r_notch(pduty); + lcd.locate(0,1); + lcd.printf("d:%3.0f%%",pduty*100); + lcd.locate(0,2); + lcd.printf("E:002 r_notch ON!"); + } + r_notch(0); + lcd.locate(0,1); + lcd.printf("d:%3.0f%%",0); + lcd.locate(0,2); + lcd.printf("E:002 Teishachu!!"); + wait(5.0); + pduty=vr2_adc.read(); + notch(pduty); + wait(1.0); + while(Asens2==XOFF){ + pduty=vr2_adc.read(); + notch(pduty); + lcd.locate(0,1); + lcd.printf("d:%3.0f%%",pduty*100); + lcd.locate(0,2); + lcd.printf("E:002 notch ON! "); + + } + notch(0); + wait(3.0); + }//while + +}//main