Displays 4 bit binary count on bar graph display. Demonstrates BusOut usage.

Dependencies:   mbed

Fork of Nightlight3 by Charles Tritt

Revision:
0:8ed2f4a2a2fe
Child:
1:4647b43d61ef
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Mar 27 12:49:02 2017 +0000
@@ -0,0 +1,39 @@
+/*
+    Project: analogRead_Overlaods
+    File: main.cpp
+    
+    Reads from analog input, streams ASCII text to std serial using printf, and
+    lights onboard LED. Also demonstrates use of floating point literal sufix to 
+    eliminate warning and int constants for HIGH and LOW. This version uses
+    overloaded operators.
+    
+    Written by: Dr. C. S. Tritt
+    Created: 3/26/17 (v. 1.0)
+    
+*/
+#include "mbed.h"
+
+const int HIGH = 1; // Optional, but makes code more readable.
+const int LOW = 0; // Optional, but makes code more readable.
+ 
+AnalogIn analog_value(A0);
+ 
+DigitalOut led(LED1);
+
+int main() {
+    float value; // Value to be read and sent to serial port.
+    
+    printf("\nAnalogIn example\n");
+    
+    while(true) {
+        value = analog_value; // Read the analog input value (0 to 1)
+        printf("Value = %f\n", value); // Send value as text via serial port.
+        if (value > 0.5f) { // Activate built-in LED. The f is optional.
+          led = HIGH;
+        }
+        else {
+          led = LOW;
+        }
+        wait(0.25); // 250 ms
+    }
+}