lab sensory - program 3

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Kuba_M
Date:
Fri Mar 27 10:54:11 2015 +0000
Commit message:
message 3

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
diff -r 000000000000 -r 9bb6505b086e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Mar 27 10:54:11 2015 +0000
@@ -0,0 +1,64 @@
+#include "mbed.h"
+
+int analog_zero_1 = 0;
+AnalogIn hallotron_silnik(PTB1);
+Serial pc(USBTX, USBRX);
+
+float voltage(AnalogIn czujnik, float zero_analog) {
+    return (czujnik.read() - zero_analog) * 2.9035;
+    }
+
+int main() {
+    pc.baud(9600);
+    int i=0; 
+    int p=0; 
+    int r=0; 
+    int k=0;
+    float o=0;
+    float m;
+    float n;
+    float suma = m;
+    float suma2 = n;
+   
+   while(true) {
+        m = voltage(hallotron_silnik, analog_zero_1);    
+        if (m > 1.5)
+        {
+        p=1;
+        }
+    for (i=0; i<10; i++)
+{
+    wait_us(10);
+m = voltage(hallotron_silnik, analog_zero_1);
+suma = suma + m;
+}
+
+    n = voltage(hallotron_silnik, analog_zero_1);
+        if (n < 0.9)
+        {
+        r = 1;
+        }
+        else r=0;
+
+    for (i=0; i<10; i++)
+{
+    wait_us(10);
+n = voltage(hallotron_silnik, analog_zero_1);
+suma2 = suma2 + n;
+}
+
+        if ((p==1) && (r==1) && (suma>suma2))
+        {
+        pc.printf("obrot\%.2f\n",o);
+        p=0;
+        o=o+0.25;
+        }
+     
+      pc.printf("%.d\n",k);
+      k++
+      wait_ms(10);
+        suma = m;
+        suma2 = n;
+        
+    }
+}
diff -r 000000000000 -r 9bb6505b086e mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Mar 27 10:54:11 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/487b796308b0
\ No newline at end of file