This program is used to verify the operations of the library SW recognize an analog port.
Dependencies: SwAnalog_LPC1768 mbed
Fork of SwAnalogInputLibraryExampleProgram by
main.cpp
00001 // ******************************************************************** 00002 // SwAnalogInput Library example program 00003 // Per pin analog port, SW recognition There are three possible. 00004 // 00005 // <schematic> 00006 // -.- mbed VOUT(+3.3[V]) 00007 // | |--------------------> mbed p20(ADinput) 00008 // | 8.2[kohm] 3.9[kohm] 2.0[kohm] | 1.0[kohm] 00009 // | --------- --------- --------- | --------- 00010 // .---| Rsw2 |---.---| Rsw1 |---.---| Rsw0 |---.---| Rout |----| 00011 // | --------- | --------- | --------- | --------- | 00012 // | ---- | ----- | ----- | | 00013 // |-----o o------.-----o o------.-----o o------| ----- 00014 // SW2 SW1 SW0 mbed GND(0[V]) 00015 // 00016 // 00017 // Accuracy of the resistance value that is within ± 1% 00018 // 00019 // <Operation details of this program> 00020 // mbed LED1 : When it detects the ON level of the SW0, and turns the LED1. 00021 // mbed LED2 : When it detects the OFF level of the SW1, and turns the LED2. 00022 // mbed LED3 : When it detects the ON edge of SW2, inverting the output to LED3. 00023 // mbed LED4 : When it detects the OFF edge of SW2, inverting the output to LED4. 00024 // 00025 // 00026 // <history> 00027 // 120212 : first edtion 00028 // 131221 : In this edition, I have changed the behavior of the program content 00029 // 00030 // ********************************************************************* 00031 00032 #include "mbed.h" 00033 #include "SwAnalog.h" 00034 00035 DigitalOut led1(LED1); 00036 DigitalOut led2(LED2); 00037 DigitalOut led3(LED3); 00038 DigitalOut led4(LED4); 00039 00040 SwAnalog sw(p20); // p20(adinput) :sw0,sw1,sw2 00041 00042 enum{ 00043 sw0 = 0, 00044 sw1, 00045 sw2 00046 }; 00047 00048 int main() { 00049 while(1) { 00050 //=========================================== 00051 // sw edge data refresh 00052 //=========================================== 00053 sw.refreshEdgeData(); 00054 00055 //=========================================== 00056 // SW level action 00057 //=========================================== 00058 // sw0 : OFF:LED1=ON ON:LED1=OFF 00059 led1 = sw.checkLevel(sw0); 00060 00061 // sw1 : OFF:LED2=OFF ON:LED2=ON 00062 led2 = !sw.checkLevel(sw1); 00063 00064 //=========================================== 00065 // SW edge action 00066 //=========================================== 00067 // sw2 on edge : LED3 invert 00068 if(sw.checkEdgeOn(sw2) == 1){ 00069 led3 = !led3; 00070 } 00071 00072 // sw2 off edge : LED4 invert 00073 if(sw.checkEdgeOff(sw2) == 1){ 00074 led4 = !led4; 00075 } 00076 } 00077 00078 00079 }
Generated on Fri Jul 15 2022 22:43:32 by 1.7.2