analog in leds show on pc terminal

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jakebonney10
Date:
Thu Oct 05 23:57:44 2017 +0000
Commit message:
Analog in led's;

Changed in this revision

Analog_IN.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r e6dc50dc9a0e Analog_IN.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Analog_IN.cpp	Thu Oct 05 23:57:44 2017 +0000
@@ -0,0 +1,62 @@
+#include "mbed.h"
+
+// Jake Bonney   
+// 10/2/17
+// OCE 360      
+// Assignment 2: Analog I/O
+
+// continuously displays an analog input value to a terminal window
+// use analog input to continuously control how many internal LEDs are on 
+
+Serial pc(USBTX, USBRX); //links usb to pc terminal
+DigitalOut myled1(LED1); //internal led
+DigitalOut myled2(LED2); //internal led
+DigitalOut myled3(LED3); //internal led
+DigitalOut myled4(LED4); //internal led
+AnalogIn Ain(p20); //Analog input
+float ADCdata;
+
+    int main() {
+         pc.printf("ADC Data Values... \n\r");
+         while (1) {
+            ADCdata=Ain;
+            pc.printf("%f \n\r",ADCdata); // sends data to terminal
+            wait (0.5);
+            
+            // all leds off
+            if (Ain <= 0.2){
+                myled1=0;
+                myled2=0;
+                myled3=0;
+                myled4=0;
+                }
+            // led1 is on
+            else if (0.2 < Ain <= 0.4){
+                myled1=1;
+                myled2=0;
+                myled3=0;
+                myled4=0;
+                }
+            // led1, led2 on
+            else if (0.4 < Ain <= 0.6){
+                myled1=1;
+                myled2=1;
+                myled3=0;
+                myled4=0;
+                }
+            // led 1,2,3 on
+            else if (0.6 < Ain <= 0.8){
+                myled1=1;
+                myled2=1;
+                myled3=1;
+                myled4=0;
+                }
+            // all leds on
+            else if (0.8 < Ain <= 1){
+                myled1=1;
+                myled2=1;
+                myled3=1;
+                myled4=1;
+                    }
+                }
+           }
diff -r 000000000000 -r e6dc50dc9a0e mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 05 23:57:44 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/235179ab3f27
\ No newline at end of file