Measure capacitances by counting rising edges of a 555 astable oscillator.
Dependencies: 4DGL-uLCD-SE mbed
main.cpp@0:292d0c987fe3, 2014-03-24 (annotated)
- Committer:
- jford38
- Date:
- Mon Mar 24 19:47:55 2014 +0000
- Revision:
- 0:292d0c987fe3
Capacitive Sensing using 555 astable oscillator
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jford38 | 0:292d0c987fe3 | 1 | #include "mbed.h" |
jford38 | 0:292d0c987fe3 | 2 | #include "capSense.h" |
jford38 | 0:292d0c987fe3 | 3 | #include "uLCD_4DGL.h" |
jford38 | 0:292d0c987fe3 | 4 | |
jford38 | 0:292d0c987fe3 | 5 | |
jford38 | 0:292d0c987fe3 | 6 | #define RA 19770 // ohms |
jford38 | 0:292d0c987fe3 | 7 | #define RB 9053 // ohms |
jford38 | 0:292d0c987fe3 | 8 | #define PERIOD 2000000 //us |
jford38 | 0:292d0c987fe3 | 9 | |
jford38 | 0:292d0c987fe3 | 10 | uLCD_4DGL uLCD(p9, p10, p11); // lcd connection |
jford38 | 0:292d0c987fe3 | 11 | CapSense cap(RA, RB, PERIOD, p21); |
jford38 | 0:292d0c987fe3 | 12 | |
jford38 | 0:292d0c987fe3 | 13 | int main() { |
jford38 | 0:292d0c987fe3 | 14 | uLCD.locate(3,5); //setting the cursor to the middle |
jford38 | 0:292d0c987fe3 | 15 | |
jford38 | 0:292d0c987fe3 | 16 | while(1) { |
jford38 | 0:292d0c987fe3 | 17 | uLCD.locate(0,6); // setting cursor |
jford38 | 0:292d0c987fe3 | 18 | float capacitance = cap.measure(); |
jford38 | 0:292d0c987fe3 | 19 | uLCD.printf("Capacitance:\n%f uF \n\n", capacitance); |
jford38 | 0:292d0c987fe3 | 20 | uLCD.printf("Frequency:\n%f Hz ",(float)cap._count/PERIOD*1000000); |
jford38 | 0:292d0c987fe3 | 21 | } |
jford38 | 0:292d0c987fe3 | 22 | } |