for BLE Nano v1 INPUT : Analog OUTPUT : USB Serial

Dependencies:   BLE_API mbed nRF51822

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002  *
00003  *    BLE Nano1 : USB Serial Communication
00004  *
00005  *    http://jellyware.jp/kurage/
00006  * 
00007  */
00008  
00009  
00010 //------------------------------------------------------------
00011 //Include Header Files
00012 //------------------------------------------------------------ 
00013 #include "mbed.h"
00014  
00015  
00016 //------------------------------------------------------------
00017 //Definition
00018 //------------------------------------------------------------ 
00019 #define ANALOG_IN_PIN1 P0_4
00020 
00021 
00022 //------------------------------------------------------------
00023 //Object generation
00024 //------------------------------------------------------------ 
00025 AnalogIn ANALOG1(ANALOG_IN_PIN1);
00026 Serial pc(P0_9, P0_11);
00027 
00028 int main(void)
00029 {
00030     pc.baud(9600);
00031     char str[10];
00032      
00033     while (true) {        
00034         float s = ANALOG1;
00035         uint16_t value = s * 1024;
00036         
00037         sprintf(str, "%d\r\n", value);
00038         pc.printf(str);
00039         
00040         wait_ms(1);
00041     }
00042 }