![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
main.cpp@0:dba2bcefd284, 2011-08-24 (annotated)
- Committer:
- gbeardall
- Date:
- Wed Aug 24 23:11:45 2011 +0000
- Revision:
- 0:dba2bcefd284
- Child:
- 1:bdb889fd3bef
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gbeardall | 0:dba2bcefd284 | 1 | #include "mbed.h" |
gbeardall | 0:dba2bcefd284 | 2 | |
gbeardall | 0:dba2bcefd284 | 3 | DigitalOut myled(LED1); |
gbeardall | 0:dba2bcefd284 | 4 | |
gbeardall | 0:dba2bcefd284 | 5 | AnalogIn hum(p20); |
gbeardall | 0:dba2bcefd284 | 6 | AnalogIn ref(p19); |
gbeardall | 0:dba2bcefd284 | 7 | |
gbeardall | 0:dba2bcefd284 | 8 | float av[5] = {0,0,0,0,0}; |
gbeardall | 0:dba2bcefd284 | 9 | |
gbeardall | 0:dba2bcefd284 | 10 | int main() { |
gbeardall | 0:dba2bcefd284 | 11 | while(1) { |
gbeardall | 0:dba2bcefd284 | 12 | |
gbeardall | 0:dba2bcefd284 | 13 | float h = hum.read(); |
gbeardall | 0:dba2bcefd284 | 14 | float r = ref.read(); |
gbeardall | 0:dba2bcefd284 | 15 | float v = 5.0*h/r; |
gbeardall | 0:dba2bcefd284 | 16 | |
gbeardall | 0:dba2bcefd284 | 17 | av[0] = av[1]; |
gbeardall | 0:dba2bcefd284 | 18 | av[1] = av[2]; |
gbeardall | 0:dba2bcefd284 | 19 | av[2] = av[3]; |
gbeardall | 0:dba2bcefd284 | 20 | av[3] = av[4]; |
gbeardall | 0:dba2bcefd284 | 21 | av[4] = v; |
gbeardall | 0:dba2bcefd284 | 22 | |
gbeardall | 0:dba2bcefd284 | 23 | float a = (av[0]+av[1]+av[2]+av[3]+av[4])/5.0; |
gbeardall | 0:dba2bcefd284 | 24 | |
gbeardall | 0:dba2bcefd284 | 25 | float m = (a-0.8)/3.0*100.0; |
gbeardall | 0:dba2bcefd284 | 26 | |
gbeardall | 0:dba2bcefd284 | 27 | printf("h=%1.2f r=%1.2f %1.2f %1.2f %3.1f\n\r", h, r, v, a, m ); |
gbeardall | 0:dba2bcefd284 | 28 | |
gbeardall | 0:dba2bcefd284 | 29 | myled = 1; |
gbeardall | 0:dba2bcefd284 | 30 | wait(0.2); |
gbeardall | 0:dba2bcefd284 | 31 | myled = 0; |
gbeardall | 0:dba2bcefd284 | 32 | wait(0.8); |
gbeardall | 0:dba2bcefd284 | 33 | } |
gbeardall | 0:dba2bcefd284 | 34 | } |