ADC & DAC Analog

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
madmonkeyman82
Date:
Thu Oct 15 16:03:59 2015 +0000
Commit message:
ADC & DAC Analog

Changed in this revision

main.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 15 16:03:59 2015 +0000
@@ -0,0 +1,51 @@
+#include "mbed.h"
+
+
+DigitalOut Vcc(PA_0);
+AnalogIn aInn(PA_1);
+DigitalOut Gnd(PA_4);
+
+
+int main()
+{
+    Vcc = 1;
+    Gnd = 0;
+    
+    float maxVoltage,minVoltage;
+    
+    maxVoltage = minVoltage = aInn.read()*3.3f;
+    
+    while(1)
+    {
+        float voltage;
+        for(int i = 0; i <= 1000; i++)
+        { 
+         voltage += aInn.read()*3.3f;
+        }
+        
+        voltage =  voltage/1000;
+        
+        if(voltage < minVoltage) minVoltage = voltage;
+        if(voltage > maxVoltage)maxVoltage = voltage;
+        
+        if(voltage <= 1.0f)
+        {
+            printf("Spening - %.3f :For lav spenning \r\n\n", voltage ); 
+        }
+        else if(voltage >= 1.0f && voltage <= 2.0f) 
+        {
+            printf("Spening - %.3f :Rikig spenning \r\n\n", voltage ); 
+        }
+        else if(voltage >= 2.0f) 
+        {
+            printf("Spening - %.3f :For hoy spenning \r\n\n", voltage );
+        }
+        
+        //printf("VoltIn: %.3f  Max: %.3f  Min: %.3f  Diff: %.3f\r\n", voltage, maxVoltage, minVoltage, maxVoltage-minVoltage);
+        
+       // printf("Voltage:\t%.3f \r\n", voltage);
+        wait_ms(200);
+    }
+        
+    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 15 16:03:59 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file