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.
Diff: main.cpp
- Revision:
- 1:0ff79bfe7bcf
- Parent:
- 0:7c52d1c30eb9
diff -r 7c52d1c30eb9 -r 0ff79bfe7bcf main.cpp
--- a/main.cpp Thu Oct 11 14:12:45 2018 +0000
+++ b/main.cpp Thu Oct 11 14:34:30 2018 +0000
@@ -1,12 +1,53 @@
+/**************************************************************
+/ ME21001 Group m-nn
+/
+/ Lab 04 Exercise 4
+/
+/ This program reads an analogue input and displays the results
+/ to the PC
+/
+/**************************************************************/
+
#include "mbed.h"
-DigitalOut myled(LED1);
+AnalogIn A_in(p17);
+PwmOut led1(LED1);
+PwmOut led2(LED2);
+PwmOut led3(LED3);
+PwmOut led4(LED4);
-int main() {
+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) {
- myled = 1;
- wait(0.2);
- myled = 0;
- wait(0.2);
+
+ 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);
}
}
+