Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-os-example-mbed5-blinky by
main.cpp
00001 #include "mbed.h" 00002 #include "adc.h" 00003 00004 DigitalOut led1(LED1); 00005 00006 // main() runs in its own thread in the OS 00007 int main() 00008 { 00009 uint16_t adc_value; 00010 unsigned int overflow; 00011 00012 /* Initialize ADC */ 00013 ADC_Init(); 00014 00015 while (true) { 00016 led1 = !led1; 00017 ADC_StartConvert(ADC_CH_0, 0, 1); // AIN0 00018 overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); 00019 printf("AIN0: 0x%04x%s\n", adc_value, overflow ? "*" : " "); 00020 ADC_StartConvert(ADC_CH_1, 0, 1); // AIN1 00021 overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); 00022 printf("AIN1: 0x%04x%s\n", adc_value, overflow ? "*" : " "); 00023 ADC_StartConvert(ADC_CH_2, 0, 1); // AIN2 00024 overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); 00025 printf("AIN2: 0x%04x%s\n", adc_value, overflow ? "*" : " "); 00026 ADC_StartConvert(ADC_CH_3, 0, 1); // AIN3 00027 overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); 00028 printf("AIN3: 0x%04x%s\n", adc_value, overflow ? "*" : " "); 00029 ADC_StartConvert(ADC_CH_0_DIV_5, 0, 1); // AIN0 div 5 00030 overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); 00031 printf("AIN0/5: 0x%04x%s\n", adc_value, overflow ? "*" : " "); 00032 ADC_StartConvert(ADC_CH_1_DIV_5, 0, 1); // AIN1 div 5 00033 overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); 00034 printf("AIN1/5: 0x%04x%s\n", adc_value, overflow ? "*" : " "); 00035 ADC_StartConvert(ADC_CH_VDDB_DIV_4, 0, 1); // AIN2 00036 overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); 00037 printf("VDDB/4: 0x%04x%s\n", adc_value, overflow ? "*" : " "); 00038 ADC_StartConvert(ADC_CH_VDD18, 0, 1); // AIN3 00039 overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); 00040 printf("VDD18: 0x%04x%s\n", adc_value, overflow ? "*" : " "); 00041 ADC_StartConvert(ADC_CH_VDD12, 0, 1); // AIN3 00042 overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); 00043 printf("VDD12: 0x%04x%s\n", adc_value, overflow ? "*" : " "); 00044 ADC_StartConvert(ADC_CH_VRTC_DIV_2, 0, 1); // AIN0 div 5 00045 overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); 00046 printf("VRTC/2: 0x%04x%s\n", adc_value, overflow ? "*" : " "); 00047 ADC_StartConvert(ADC_CH_TMON, 0, 1); // AIN1 div 5 00048 overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); 00049 printf("TMON: 0x%04x%s\n", adc_value, overflow ? "*" : " "); 00050 wait(0.5); 00051 } 00052 } 00053
Generated on Thu Jul 14 2022 23:57:06 by
1.7.2
