トランジスタ技術2015年6月号mbedラジコン・カーp179 リスト2 障害物検知器のmbedメイン・プログラム

Dependencies:   mbed

Committer:
YoshihitoShimada
Date:
Mon Jun 01 02:46:57 2015 +0000
Revision:
0:bb79ff3ee321
sonar test program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YoshihitoShimada 0:bb79ff3ee321 1 #include "mbed.h"
YoshihitoShimada 0:bb79ff3ee321 2
YoshihitoShimada 0:bb79ff3ee321 3 PwmOut S40kHz(P0_21);
YoshihitoShimada 0:bb79ff3ee321 4
YoshihitoShimada 0:bb79ff3ee321 5 AnalogIn Ain(P0_13);
YoshihitoShimada 0:bb79ff3ee321 6
YoshihitoShimada 0:bb79ff3ee321 7 DigitalOut StopSignal(P0_20);
YoshihitoShimada 0:bb79ff3ee321 8
YoshihitoShimada 0:bb79ff3ee321 9 int main() {
YoshihitoShimada 0:bb79ff3ee321 10
YoshihitoShimada 0:bb79ff3ee321 11 float threshold=0.2;
YoshihitoShimada 0:bb79ff3ee321 12
YoshihitoShimada 0:bb79ff3ee321 13 S40kHz.period_us(25); // 40kHz
YoshihitoShimada 0:bb79ff3ee321 14 S40kHz.pulsewidth_us(12.5);
YoshihitoShimada 0:bb79ff3ee321 15
YoshihitoShimada 0:bb79ff3ee321 16 while (1) {
YoshihitoShimada 0:bb79ff3ee321 17 if(Ain > threshold) {
YoshihitoShimada 0:bb79ff3ee321 18 StopSignal=0; // Red LED ON
YoshihitoShimada 0:bb79ff3ee321 19 } else {
YoshihitoShimada 0:bb79ff3ee321 20 StopSignal=1; // Red LED OFF
YoshihitoShimada 0:bb79ff3ee321 21 }
YoshihitoShimada 0:bb79ff3ee321 22 }
YoshihitoShimada 0:bb79ff3ee321 23 }