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.
main.cpp@1:0ff79bfe7bcf, 2018-10-11 (annotated)
- Committer:
- czrooney
- Date:
- Thu Oct 11 14:34:30 2018 +0000
- Revision:
- 1:0ff79bfe7bcf
- Parent:
- 0:7c52d1c30eb9
;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| czrooney | 1:0ff79bfe7bcf | 1 | /************************************************************** |
| czrooney | 1:0ff79bfe7bcf | 2 | / ME21001 Group m-nn |
| czrooney | 1:0ff79bfe7bcf | 3 | / |
| czrooney | 1:0ff79bfe7bcf | 4 | / Lab 04 Exercise 4 |
| czrooney | 1:0ff79bfe7bcf | 5 | / |
| czrooney | 1:0ff79bfe7bcf | 6 | / This program reads an analogue input and displays the results |
| czrooney | 1:0ff79bfe7bcf | 7 | / to the PC |
| czrooney | 1:0ff79bfe7bcf | 8 | / |
| czrooney | 1:0ff79bfe7bcf | 9 | /**************************************************************/ |
| czrooney | 1:0ff79bfe7bcf | 10 | |
| czrooney | 0:7c52d1c30eb9 | 11 | #include "mbed.h" |
| czrooney | 0:7c52d1c30eb9 | 12 | |
| czrooney | 1:0ff79bfe7bcf | 13 | AnalogIn A_in(p17); |
| czrooney | 1:0ff79bfe7bcf | 14 | PwmOut led1(LED1); |
| czrooney | 1:0ff79bfe7bcf | 15 | PwmOut led2(LED2); |
| czrooney | 1:0ff79bfe7bcf | 16 | PwmOut led3(LED3); |
| czrooney | 1:0ff79bfe7bcf | 17 | PwmOut led4(LED4); |
| czrooney | 0:7c52d1c30eb9 | 18 | |
| czrooney | 1:0ff79bfe7bcf | 19 | int main() { |
| czrooney | 1:0ff79bfe7bcf | 20 | |
| czrooney | 1:0ff79bfe7bcf | 21 | float analogue_val = 0.0; |
| czrooney | 1:0ff79bfe7bcf | 22 | |
| czrooney | 1:0ff79bfe7bcf | 23 | led1.period(0.020); |
| czrooney | 1:0ff79bfe7bcf | 24 | led2.period(0.020); |
| czrooney | 1:0ff79bfe7bcf | 25 | led3.period(0.020); |
| czrooney | 1:0ff79bfe7bcf | 26 | led4.period(0.020); |
| czrooney | 1:0ff79bfe7bcf | 27 | |
| czrooney | 0:7c52d1c30eb9 | 28 | while(1) { |
| czrooney | 1:0ff79bfe7bcf | 29 | |
| czrooney | 1:0ff79bfe7bcf | 30 | analogue_val = A_in.read(); |
| czrooney | 1:0ff79bfe7bcf | 31 | |
| czrooney | 1:0ff79bfe7bcf | 32 | if (analogue_val<0.25) { |
| czrooney | 1:0ff79bfe7bcf | 33 | led1=(analogue_val/0.25); |
| czrooney | 1:0ff79bfe7bcf | 34 | led2=led3=led4=0; |
| czrooney | 1:0ff79bfe7bcf | 35 | } |
| czrooney | 1:0ff79bfe7bcf | 36 | else if (analogue_val<0.5){ |
| czrooney | 1:0ff79bfe7bcf | 37 | led1=1; |
| czrooney | 1:0ff79bfe7bcf | 38 | led2=((analogue_val-0.25)/0.25); |
| czrooney | 1:0ff79bfe7bcf | 39 | led3=led4=0; |
| czrooney | 1:0ff79bfe7bcf | 40 | } |
| czrooney | 1:0ff79bfe7bcf | 41 | else if (analogue_val<0.75){ |
| czrooney | 1:0ff79bfe7bcf | 42 | led1=led2=1; |
| czrooney | 1:0ff79bfe7bcf | 43 | led3=((analogue_val-0.5)/0.25); |
| czrooney | 1:0ff79bfe7bcf | 44 | led4=0; |
| czrooney | 1:0ff79bfe7bcf | 45 | } |
| czrooney | 1:0ff79bfe7bcf | 46 | else { |
| czrooney | 1:0ff79bfe7bcf | 47 | led1=led2=led3=1; |
| czrooney | 1:0ff79bfe7bcf | 48 | led4=((analogue_val-0.75)/0.25); |
| czrooney | 1:0ff79bfe7bcf | 49 | } |
| czrooney | 1:0ff79bfe7bcf | 50 | wait (0.100); |
| czrooney | 0:7c52d1c30eb9 | 51 | } |
| czrooney | 0:7c52d1c30eb9 | 52 | } |
| czrooney | 1:0ff79bfe7bcf | 53 |