エレキジャックweb mbed入門 mbed RMCS鉄道模型自動制御システム 課題10です。単線ですが、ポイントを一つ設置して2列車を交互運転できるレイアウトです3アクティブ光センサ、1ポイントを設置しています。コンパクトに小型アルミトランクに組み込みました。

Committer:
takeuchi
Date:
Sun Feb 19 07:54:27 2012 +0000
Revision:
0:f3675b6d19ef

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takeuchi 0:f3675b6d19ef 1 // mRMCS10 Active sensor
takeuchi 0:f3675b6d19ef 2 // Trunk rayout tansen oufuku
takeuchi 0:f3675b6d19ef 3 // mbed RailModelContorolSystem
takeuchi 0:f3675b6d19ef 4
takeuchi 0:f3675b6d19ef 5 #include "mbed.h"
takeuchi 0:f3675b6d19ef 6 #include "TextLCD0420.h"
takeuchi 0:f3675b6d19ef 7
takeuchi 0:f3675b6d19ef 8 #define ON 1
takeuchi 0:f3675b6d19ef 9 #define OFF 0
takeuchi 0:f3675b6d19ef 10 #define XON 0
takeuchi 0:f3675b6d19ef 11 #define XOFF 1
takeuchi 0:f3675b6d19ef 12
takeuchi 0:f3675b6d19ef 13 DigitalOut mled1(LED1);
takeuchi 0:f3675b6d19ef 14 DigitalOut mled2(LED2);
takeuchi 0:f3675b6d19ef 15 DigitalOut mled3(LED3);
takeuchi 0:f3675b6d19ef 16 DigitalOut mled4(LED4);
takeuchi 0:f3675b6d19ef 17 AnalogIn vr1_adc(p15);
takeuchi 0:f3675b6d19ef 18 AnalogIn vr2_adc(p16);
takeuchi 0:f3675b6d19ef 19 DigitalIn sens1(p17);
takeuchi 0:f3675b6d19ef 20 DigitalIn sens2(p18);
takeuchi 0:f3675b6d19ef 21 DigitalIn sens3(p19);
takeuchi 0:f3675b6d19ef 22 PwmOut r1_pwm(p22);
takeuchi 0:f3675b6d19ef 23 PwmOut r2_pwm(p23);
takeuchi 0:f3675b6d19ef 24 DigitalOut po10(p5);
takeuchi 0:f3675b6d19ef 25 DigitalOut po11(p6);
takeuchi 0:f3675b6d19ef 26 DigitalOut po20(p7);
takeuchi 0:f3675b6d19ef 27 DigitalOut po21(p8);
takeuchi 0:f3675b6d19ef 28 DigitalIn Asens1(p9);
takeuchi 0:f3675b6d19ef 29 DigitalIn Asens2(p10);
takeuchi 0:f3675b6d19ef 30 DigitalIn Asens3(p11);
takeuchi 0:f3675b6d19ef 31
takeuchi 0:f3675b6d19ef 32 TextLCD lcd(p24, p25, p26, p27, p28, p29, p30,20,4); // rs, rw, e, d0, d1, d2, d3
takeuchi 0:f3675b6d19ef 33
takeuchi 0:f3675b6d19ef 34 float pduty,pduty_slow;
takeuchi 0:f3675b6d19ef 35
takeuchi 0:f3675b6d19ef 36 void notch(float duty){
takeuchi 0:f3675b6d19ef 37 r1_pwm.write(duty);
takeuchi 0:f3675b6d19ef 38 r2_pwm.write(0);
takeuchi 0:f3675b6d19ef 39 }
takeuchi 0:f3675b6d19ef 40
takeuchi 0:f3675b6d19ef 41 void r_notch(float duty){
takeuchi 0:f3675b6d19ef 42 r1_pwm.write(0);
takeuchi 0:f3675b6d19ef 43 r2_pwm.write(duty);
takeuchi 0:f3675b6d19ef 44 }
takeuchi 0:f3675b6d19ef 45
takeuchi 0:f3675b6d19ef 46 void point1(int x){
takeuchi 0:f3675b6d19ef 47 if(x==0){
takeuchi 0:f3675b6d19ef 48 po10=ON;
takeuchi 0:f3675b6d19ef 49 po11=OFF;
takeuchi 0:f3675b6d19ef 50 wait(0.2);
takeuchi 0:f3675b6d19ef 51 po10=OFF;
takeuchi 0:f3675b6d19ef 52 po11=OFF;
takeuchi 0:f3675b6d19ef 53 }
takeuchi 0:f3675b6d19ef 54 else if(x==1){
takeuchi 0:f3675b6d19ef 55 po10=OFF;
takeuchi 0:f3675b6d19ef 56 po11=ON;
takeuchi 0:f3675b6d19ef 57 wait(0.2);
takeuchi 0:f3675b6d19ef 58 po10=OFF;
takeuchi 0:f3675b6d19ef 59 po11=OFF;
takeuchi 0:f3675b6d19ef 60 }
takeuchi 0:f3675b6d19ef 61 }
takeuchi 0:f3675b6d19ef 62
takeuchi 0:f3675b6d19ef 63 int main() {
takeuchi 0:f3675b6d19ef 64 int i,count,ressha,init_sts;
takeuchi 0:f3675b6d19ef 65 float pduty;
takeuchi 0:f3675b6d19ef 66 r1_pwm.pulsewidth(0.000001);//1us=0.000001
takeuchi 0:f3675b6d19ef 67 r1_pwm.period(0.00001);//1ms=0.001s
takeuchi 0:f3675b6d19ef 68 r2_pwm.pulsewidth(0.000001);//1us=0.000001
takeuchi 0:f3675b6d19ef 69 r2_pwm.period(0.00001);//1ms=0.001s
takeuchi 0:f3675b6d19ef 70
takeuchi 0:f3675b6d19ef 71 lcd.cls();
takeuchi 0:f3675b6d19ef 72 lcd.locate(0,0);
takeuchi 0:f3675b6d19ef 73 lcd.printf("Set Train on rail!!");
takeuchi 0:f3675b6d19ef 74 lcd.locate(0,1);
takeuchi 0:f3675b6d19ef 75 lcd.printf("==>Sns1:XON,Sns2:XON");
takeuchi 0:f3675b6d19ef 76
takeuchi 0:f3675b6d19ef 77 notch(0);
takeuchi 0:f3675b6d19ef 78 init_sts=1;
takeuchi 0:f3675b6d19ef 79 ressha=0;
takeuchi 0:f3675b6d19ef 80 while(init_sts==1){
takeuchi 0:f3675b6d19ef 81 if(Asens1==XON && Asens2==XON){
takeuchi 0:f3675b6d19ef 82 lcd.cls();
takeuchi 0:f3675b6d19ef 83 lcd.locate(0,0);
takeuchi 0:f3675b6d19ef 84 lcd.printf("** mbed RMCS **");
takeuchi 0:f3675b6d19ef 85 lcd.locate(0,1);
takeuchi 0:f3675b6d19ef 86 lcd.printf("> Pse Main pwr on!");
takeuchi 0:f3675b6d19ef 87 lcd.locate(0,1);
takeuchi 0:f3675b6d19ef 88 lcd.printf("> System start ...");
takeuchi 0:f3675b6d19ef 89 wait(1.0);
takeuchi 0:f3675b6d19ef 90 point1(0);
takeuchi 0:f3675b6d19ef 91 wait(1.0);
takeuchi 0:f3675b6d19ef 92 point1(1);
takeuchi 0:f3675b6d19ef 93 wait(1.0);
takeuchi 0:f3675b6d19ef 94 point1(0);
takeuchi 0:f3675b6d19ef 95 wait(1.0);
takeuchi 0:f3675b6d19ef 96 init_sts=0;
takeuchi 0:f3675b6d19ef 97 }
takeuchi 0:f3675b6d19ef 98 }
takeuchi 0:f3675b6d19ef 99
takeuchi 0:f3675b6d19ef 100 lcd.cls();
takeuchi 0:f3675b6d19ef 101 lcd.locate(0,0);
takeuchi 0:f3675b6d19ef 102 lcd.printf("** mbed RMCS10 **");
takeuchi 0:f3675b6d19ef 103
takeuchi 0:f3675b6d19ef 104 while(1){
takeuchi 0:f3675b6d19ef 105
takeuchi 0:f3675b6d19ef 106 lcd.locate(0,3);
takeuchi 0:f3675b6d19ef 107 lcd.printf("Point1 0");
takeuchi 0:f3675b6d19ef 108 point1(0);
takeuchi 0:f3675b6d19ef 109
takeuchi 0:f3675b6d19ef 110 pduty=vr1_adc.read();
takeuchi 0:f3675b6d19ef 111 r_notch(pduty);
takeuchi 0:f3675b6d19ef 112 wait(1.0);
takeuchi 0:f3675b6d19ef 113 while(Asens3==XOFF){
takeuchi 0:f3675b6d19ef 114 pduty=vr1_adc.read();
takeuchi 0:f3675b6d19ef 115 r_notch(pduty);
takeuchi 0:f3675b6d19ef 116 lcd.locate(0,1);
takeuchi 0:f3675b6d19ef 117 lcd.printf("d:%3.0f%%",pduty*100);
takeuchi 0:f3675b6d19ef 118 lcd.locate(0,2);
takeuchi 0:f3675b6d19ef 119 lcd.printf("E:001 r_notch ON!");
takeuchi 0:f3675b6d19ef 120 }
takeuchi 0:f3675b6d19ef 121 r_notch(0);
takeuchi 0:f3675b6d19ef 122 lcd.locate(0,1);
takeuchi 0:f3675b6d19ef 123 lcd.printf("d:%3.0f%%",0);
takeuchi 0:f3675b6d19ef 124 lcd.locate(0,2);
takeuchi 0:f3675b6d19ef 125 lcd.printf("E:001 Teishachu!!");
takeuchi 0:f3675b6d19ef 126 wait(5.0);
takeuchi 0:f3675b6d19ef 127 pduty=vr1_adc.read();
takeuchi 0:f3675b6d19ef 128 notch(pduty);
takeuchi 0:f3675b6d19ef 129 wait(1.0);
takeuchi 0:f3675b6d19ef 130 while(Asens1==XOFF){
takeuchi 0:f3675b6d19ef 131 pduty=vr1_adc.read();
takeuchi 0:f3675b6d19ef 132 notch(pduty);
takeuchi 0:f3675b6d19ef 133 lcd.locate(0,1);
takeuchi 0:f3675b6d19ef 134 lcd.printf("d:%3.0f%%",pduty*100);
takeuchi 0:f3675b6d19ef 135 lcd.locate(0,2);
takeuchi 0:f3675b6d19ef 136 lcd.printf("E:001 notch ON! ");
takeuchi 0:f3675b6d19ef 137
takeuchi 0:f3675b6d19ef 138 }
takeuchi 0:f3675b6d19ef 139 notch(0);
takeuchi 0:f3675b6d19ef 140 wait(3.0);
takeuchi 0:f3675b6d19ef 141
takeuchi 0:f3675b6d19ef 142 lcd.locate(0,3);
takeuchi 0:f3675b6d19ef 143 lcd.printf("Point1 1");
takeuchi 0:f3675b6d19ef 144
takeuchi 0:f3675b6d19ef 145 point1(1);
takeuchi 0:f3675b6d19ef 146 wait(1.0);
takeuchi 0:f3675b6d19ef 147 pduty=vr2_adc.read();
takeuchi 0:f3675b6d19ef 148 r_notch(pduty);
takeuchi 0:f3675b6d19ef 149 wait(1.0);
takeuchi 0:f3675b6d19ef 150 while(Asens3==XOFF){
takeuchi 0:f3675b6d19ef 151 pduty=vr2_adc.read();
takeuchi 0:f3675b6d19ef 152 r_notch(pduty);
takeuchi 0:f3675b6d19ef 153 lcd.locate(0,1);
takeuchi 0:f3675b6d19ef 154 lcd.printf("d:%3.0f%%",pduty*100);
takeuchi 0:f3675b6d19ef 155 lcd.locate(0,2);
takeuchi 0:f3675b6d19ef 156 lcd.printf("E:002 r_notch ON!");
takeuchi 0:f3675b6d19ef 157 }
takeuchi 0:f3675b6d19ef 158 r_notch(0);
takeuchi 0:f3675b6d19ef 159 lcd.locate(0,1);
takeuchi 0:f3675b6d19ef 160 lcd.printf("d:%3.0f%%",0);
takeuchi 0:f3675b6d19ef 161 lcd.locate(0,2);
takeuchi 0:f3675b6d19ef 162 lcd.printf("E:002 Teishachu!!");
takeuchi 0:f3675b6d19ef 163 wait(5.0);
takeuchi 0:f3675b6d19ef 164 pduty=vr2_adc.read();
takeuchi 0:f3675b6d19ef 165 notch(pduty);
takeuchi 0:f3675b6d19ef 166 wait(1.0);
takeuchi 0:f3675b6d19ef 167 while(Asens2==XOFF){
takeuchi 0:f3675b6d19ef 168 pduty=vr2_adc.read();
takeuchi 0:f3675b6d19ef 169 notch(pduty);
takeuchi 0:f3675b6d19ef 170 lcd.locate(0,1);
takeuchi 0:f3675b6d19ef 171 lcd.printf("d:%3.0f%%",pduty*100);
takeuchi 0:f3675b6d19ef 172 lcd.locate(0,2);
takeuchi 0:f3675b6d19ef 173 lcd.printf("E:002 notch ON! ");
takeuchi 0:f3675b6d19ef 174
takeuchi 0:f3675b6d19ef 175 }
takeuchi 0:f3675b6d19ef 176 notch(0);
takeuchi 0:f3675b6d19ef 177 wait(3.0);
takeuchi 0:f3675b6d19ef 178 }//while
takeuchi 0:f3675b6d19ef 179
takeuchi 0:f3675b6d19ef 180 }//main