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

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 PwmOut S40kHz(P0_21);
00004 
00005 AnalogIn Ain(P0_13);
00006 
00007 DigitalOut StopSignal(P0_20);
00008 
00009 int main() {
00010 
00011     float threshold=0.2;
00012 
00013     S40kHz.period_us(25);          // 40kHz
00014     S40kHz.pulsewidth_us(12.5);
00015 
00016     while (1) {
00017         if(Ain > threshold) {
00018             StopSignal=0;         // Red LED ON
00019         } else {
00020             StopSignal=1;         // Red LED OFF
00021         }
00022     }
00023 }