![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Nucleo_display_temp_LM35
Revision 2:db3ce8717e38, committed 2016-10-20
- Comitter:
- anywill
- Date:
- Thu Oct 20 13:50:30 2016 +0000
- Parent:
- 1:b78c70e272ae
- Commit message:
- PIR????
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r b78c70e272ae -r db3ce8717e38 main.cpp --- a/main.cpp Thu Oct 20 09:11:55 2016 +0000 +++ b/main.cpp Thu Oct 20 13:50:30 2016 +0000 @@ -1,22 +1,33 @@ //平台nucleo 70r+mbed -//USB虚拟串口与PC串口通信 -//波特率9600,无奇偶校验 +//Pir红外人体感应模块HC-SR501 +//感应人体后LED1亮 +// By www.emcu.it +// Feb.2015 +// Tested on NUCLEO-F410RE +// #include "mbed.h" -Serial pc(SERIAL_TX, SERIAL_RX); // 虚拟 USART2 tx, rx -Serial device(PB_6, PA_10); // PC机usb转TTL CP2102 USART1 tx, rx - +DigitalOut myled(LED1);//D13 +DigitalIn Sensor(PA_10); +int n=0; int main() { - while(1) - { - if(pc.readable()) - { - device.putc(pc.getc()); // 从虚拟串口接收数据,并发给PC - - } - if(device.readable()) - { - pc.putc(device.getc()); // 从PC物理串口接收数据,并发给虚拟串口 - } - } -} + // 等待感应模块稳定(30 sec.) + for (n=0; n<30; n++) + { + wait_ms(1000); // 1sec delay + + myled = !myled; // Blinking LED1 + } + myled = 0; // LED1 is OFF + + while(1) + { + if (Sensor == 1) + { + myled = 1; // LED1 is ON + wait_ms(20000); // LED1 亮 20 sec + } + else + myled = 0; // LED1 灭 + } +} \ No newline at end of file