/** comparatorin_demo * Simple program to demonstrate the basic functions * of the analog comparator of the FRDM-KL25Z board. * * Used library: * - ComparatorIn //https://developer.mbed.org/users/frankvnk/code/ComparatorIn/ * written by Frank Vannieuwkerke * * Hardware requirements: * - FRDM-KL25 board * - CdS photoresistor pulled up by 10 k * - Connecect the midpoint of the divider to PTE29 * * 10k CdS photoresistor * +3.3V --/\/\/\---+---/\/\/\---- GND * | * PTE29 * */
Dependencies: ComparatorIn mbed
Fork of 05_comparator_demo by
main.cpp
00001 /** 05_comparator_demo 00002 * Simple program to demonstrate the basic functions 00003 * of the analog comparator of the FRDM-KL25Z board. 00004 * 00005 * Used library: 00006 * - ComparatorIn //https://developer.mbed.org/users/frankvnk/code/ComparatorIn/ 00007 * written by Frank Vannieuwkerke 00008 * 00009 * Hardware requirements: 00010 * - FRDM-KL25 board 00011 * - CdS photoresistor pulled up by 10 k 00012 * - Connecect the midpoint of the divider to PTE29 00013 * 00014 * 10k CdS photoresistor 00015 * +3.3V --/\/\/\---+---/\/\/\---- GND 00016 * | 00017 * PTE29 00018 * 00019 */ 00020 00021 #include "mbed.h" 00022 #include "ComparatorIn.h" 00023 00024 DigitalOut blinker (LED_BLUE); // blinking LED 00025 DigitalOut cmpled (LED_GREEN); // signing comparator status 00026 AnalogIn cmp_lvl (PTE29); // ADC input to check comparator input 00027 ComparatorIn compi(PTE29, PTE30); // in+ = PTE29, in- = 12-bit DAC 00028 00029 // Comparator interrupt callback functions 00030 void cmp_rise_ISR(void) 00031 { 00032 cmpled = 0; // LED ON at rising edge 00033 } 00034 00035 void cmp_fall_ISR(void) 00036 { 00037 cmpled = 1; // LED OFF at falling edge 00038 } 00039 00040 00041 00042 int main() 00043 { 00044 cmpled = 1; // LED OFF at the beginning 00045 00046 compi.rising(&cmp_rise_ISR); // Set pointer to rising interrupt function 00047 compi.falling(&cmp_fall_ISR); // Set pointer to falling interrupt function 00048 compi.treshold(0.3); // Set comparator threshold to 1V = 0.3 * 3.3V 00049 00050 while(1) 00051 { 00052 printf("Light sensor : %7.5f Volt\n",cmp_lvl*3.3); 00053 blinker = 1; // binking LED OFF 00054 wait(2); // wait for 2 sec 00055 blinker = 0; // blinking LED ON 00056 wait(0.2); 00057 if (compi.status() == 0x01) // poll comparator status 00058 { 00059 printf("*** Treshold reached : %7.5f\n",cmp_lvl*3.3); 00060 } 00061 } 00062 } 00063 00064
Generated on Thu Jul 21 2022 20:02:31 by 1.7.2