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
- Committer:
- czrooney
- Date:
- 2018-10-11
- Revision:
- 1:0ff79bfe7bcf
- Parent:
- 0:7c52d1c30eb9
File content as of revision 1:0ff79bfe7bcf:
/**************************************************************
/ ME21001 Group m-nn
/
/ Lab 04 Exercise 4
/
/ This program reads an analogue input and displays the results
/ to the PC
/
/**************************************************************/
#include "mbed.h"
AnalogIn A_in(p17);
PwmOut led1(LED1);
PwmOut led2(LED2);
PwmOut led3(LED3);
PwmOut led4(LED4);
int main() {
float analogue_val = 0.0;
led1.period(0.020);
led2.period(0.020);
led3.period(0.020);
led4.period(0.020);
while(1) {
analogue_val = A_in.read();
if (analogue_val<0.25) {
led1=(analogue_val/0.25);
led2=led3=led4=0;
}
else if (analogue_val<0.5){
led1=1;
led2=((analogue_val-0.25)/0.25);
led3=led4=0;
}
else if (analogue_val<0.75){
led1=led2=1;
led3=((analogue_val-0.5)/0.25);
led4=0;
}
else {
led1=led2=led3=1;
led4=((analogue_val-0.75)/0.25);
}
wait (0.100);
}
}