Iain Veitch / Mbed 2 deprecated ME21001_Lab04_Exercise_04

Dependencies:   mbed

Revision:
0:a06d2b459821
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 16 17:54:19 2018 +0000
@@ -0,0 +1,59 @@
+/**************************************************************
+/ ME21001 Group m-nn
+/
+/ Lab 04 Exercise 4
+/
+/ This program reads an analogue input and displays the results
+/ to the PC
+/
+*/
+#include "mbed.h"
+Serial pc(USBTX, USBRX);    // USB serial interface
+
+AnalogIn A_in(p17);         // analogue input pin for reference values
+PwmOut led1(LED1);
+PwmOut led2(LED2);
+PwmOut led3(LED3);
+PwmOut led4(LED4);
+int main() {
+    
+float analogue_val=0.0;     // variable to hold the analogue input 
+                            // values as decimals
+                            // set the USB serial interface baud rate
+led1.period(0.020);
+led2.period(0.020);
+led3.period(0.020);
+led4.period(0.020);
+
+
+    while(1) {              // repeat indefinitely
+
+                            // read the voltage on the analogue input pin and 
+                            // convert it to a
+                            // decimal number with 12-bit resolution
+
+analogue_val = A_in.read(); // export the readings to a terminal program 
+                            // via the USB cable
+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.l);
+                }
+          }      
+        
+