Blue LDM test for CP4

Dependencies:   mbed

Revision:
1:5c0202cb8e6d
Parent:
0:c57b9d018b9f
Child:
2:a29fc54a61cb
--- a/main.cpp	Wed Dec 12 15:13:50 2018 +0000
+++ b/main.cpp	Tue Dec 18 18:10:14 2018 +0000
@@ -1,29 +1,86 @@
 #include "mbed.h"
+#include <string>
 
 Serial pc(USBTX, USBRX); // tx, rx
-PwmOut led1(p23);
-PwmOut led2(p24);
-PwmOut led3(p25);
+PwmOut mclk(p24);
+DigitalOut mout1(p15);
+DigitalOut mout2(p28);
+InterruptIn mIn(p21);
+
+AnalogOut mA(p18);
 
 float brightness = 1.0;
 
+
+void handler()
+{
+    mout2 = 1;
+    wait(0.25);
+    mout2 = 0;
+}
+
+void blink( int n )
+{
+    for(int i = 0; i<5; i++)
+    {
+        mout1 = 1;
+        wait(0.25);
+        mout1 = 0;
+    }
+}
+
+
 int main() {
-    pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n");
-
+    pc.printf("Enter Voltaage and Press Enter\n\r");
+    string instr;
+    float voltage;
+    
+    mIn.rise(&handler);
+    
+    mclk.period_us(400);
+    mclk.write(0.50);
+    
     while(1) {
         char c = pc.getc();
+        
+        if( c == 13 )
+        {
+            voltage = atof( instr.c_str() );
+            
+            if( voltage == 0 || voltage > 3.3 )
+            {
+                pc.printf("ERROR\n\r");
+            }
+            else
+            {
+                mA.write( voltage / 3.3 );
+                pc.printf("Voltage set to %3fV\n\r", voltage);
+            }
+            
+            instr.clear();
+            
+        }
+        
+        else
+        {
+            instr.push_back(c);
+        }
+        
         if((c == 'u') && (brightness < 1.0)) {
             brightness += 0.01;
-            led1 = brightness;
-            led2 = brightness;
-            led3 = brightness;
+
         }
         if((c == 'd') && (brightness > 0.0)) {
             brightness -= 0.01;
-            led1 = brightness;
-            led2 = brightness;
-            led3 = brightness; 
+
         } 
+        
+        if( c == 'b' && brightness <= 1.0)
+        {
+            blink(5);
+        }
+        
+        
 
     }
 }
\ No newline at end of file