zhi board板载一个电位器,连接在PC_5引脚,这个引脚可做为模拟量输入。

Dependencies:   mbed

Fork of zhi_board_analog_pc5 by barryzxy zhang

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 //zhi board led1 = PC_6 led2 = PC_8
00003 DigitalOut led1(PC_6);
00004 DigitalOut led2(PC_8);
00005 //
00006 Serial usb2ser(PA_9, PA_10);
00007 
00008 AnalogIn ain(PC_5);
00009  
00010 int main() 
00011 {
00012     unsigned short ai_pc_5;
00013   
00014     while(1) 
00015     {
00016         //fuxiaojun
00017         ai_pc_5 = ain.read_u16();
00018         usb2ser.printf ("pc_5= %d\n",ai_pc_5);       
00019         led1 = 1; // LED is ON
00020         led2 = 0;
00021         wait(0.2); // 200 ms
00022         led1 = 0; // LED is OFF
00023         led2 = 1;
00024         wait(0.2); // 1 sec
00025     }
00026 }