Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:a9bfbb95c112, committed 2015-08-06
- Comitter:
- kohacraft
- Date:
- Thu Aug 06 00:05:29 2015 +0000
- Commit message:
- ver1.0 traffic signal
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Aug 06 00:05:29 2015 +0000 @@ -0,0 +1,101 @@ +#include "mbed.h" + +DigitalOut B(dp17); //自動車用信号 青 +DigitalOut Y(dp16); // 黄 +DigitalOut R(dp15); // 赤 +DigitalOut B2(dp13); //歩行者用信号 青 +DigitalOut R2(dp14); // 赤 +DigitalOut buzz(dp28); //スピーカー + +DigitalIn sw(dp26); //押しボタンスイッチ + +int main() { + while(1) { + + B = 1; //自動車:5秒間青 + Y = 0; //1がLED ON 0がLED OFF + R = 0; + B2 = 0; //歩行者:赤 + R2 = 1; + wait(5.0); //5秒間 + + while( sw == 0 ) + { + } + + B = 0; //自動車:1秒間黄色 + Y = 1; + R = 0; + B2 = 0; + R2 = 1; + wait(1.0); + + B = 0; //自動車:2秒間赤 + Y = 0; + R = 1; + B2 = 0; //歩行者:赤のまま + R2 = 1; + wait(2.0); + + //歩行者の信号を青にする + B = 0; //自動車:赤のまま + Y = 0; + R = 1; + B2 = 1; //歩行者:青にする + R2 = 0; + + //カッコーを5回鳴らす + for( int i=0 ; i<5 ; i++ ) + { + //ミの音を鳴らす + for( int i=0 ; i<300 ; i++ ) + { + buzz = 1; //スピーカーをON OFF させて音を作る + wait(1.0/880.00/4); //1オクターブ上のミ 880*2Hz + buzz = 0; + wait(1.0/880.00/4); + + } + wait(0.2); + + //ドの音を鳴らす + for( int i=0 ; i<700 ; i++ ) + { + + buzz = 0; + wait(1.0/698.45/4); //1オクターブ上のド 698.45*2Hz + buzz = 1; + wait(1.0/698.45/4); + + } + wait(0.8); + } + + //歩行者用信号を点滅させる + for( int i=0 ; i<5 ; i++ ) + { + B = 0; + Y = 0; + R = 1; + B2 = 1; //歩行者:青を消光らす + R2 = 0; + wait(0.3); + + B = 0; + Y = 0; + R = 1; + B2 = 0; //歩行者:青を消す + R2 = 0; + wait(0.3); + } + + B = 0; + Y = 0; + R = 1; + B2 = 0; + R2 = 1; //歩行者:赤を消光らす + wait(2.0); + + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Aug 06 00:05:29 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/da0ca467f8b5 \ No newline at end of file