mag niet van hendrik D:

Dependencies:   mbed MatrixMath QEI HIDScope Matrix biquadFilter MODSERIAL FastPWM

Files at this revision

API Documentation at this revision

Comitter:
Hendrikvg
Date:
Fri Sep 20 07:09:28 2019 +0000
Parent:
9:12b9865e7373
Child:
11:008c8060e640
Commit message:
Scope met potentiometer werkt

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
--- a/main.cpp	Thu Sep 19 14:41:31 2019 +0000
+++ b/main.cpp	Fri Sep 20 07:09:28 2019 +0000
@@ -1,6 +1,9 @@
 #include "mbed.h"
+#include "HIDScope.h"
 
 Serial pc(USBTX,USBRX);
+HIDScope scope(2);
+Ticker AInTicker;
 InterruptIn BUT1(D1);
 InterruptIn BUT2(D0);
 PwmOut lichtje(D3);
@@ -9,33 +12,45 @@
 float getal;
 int n=5;
 
+volatile float x;
+volatile float x_prev=0; 
+volatile float y;
+
+void ReadAnalogInAndFilter()
+{
+    x = ain;   // Capture data
+    scope.set(0, x);   // store data in first element of scope memory
+    y = (x_prev+ x)/2.0;   // averaging
+    scope.set(1, y);// store data in second element of scope memory filter
+    x_prev= x; // Prepare for next round
+
+    scope.send(); // send what's in scope memory to PC
+}
+
 void plus()
 {
     n++; // n=n+1
-    if (n>10){
+    if (n>10) {
         n=10;
-        }
     }
-    
+}
+
 void min()
 {
     n--;
-    if (n<0){
+    if (n<0) {
         n=0;
-        }
     }
+}
 
 int main() {
     pc.baud(115200);
     lichtje=1;
     BUT1.fall(plus);
     BUT2.fall(min);
+    AInTicker.attach(&ReadAnalogInAndFilter, 0.01);
         while(true)
             {
-                    getal = 0.01*n*ain.read();
-                   lichtje.period(4.0f);  // 4 second period
-                    lichtje.write(getal);  // duty cycle
-                    pc.printf("%3.3f%\n\r", ain.read());
-        
+       
     }
 }
\ No newline at end of file
--- a/mbed.bld	Thu Sep 19 14:41:31 2019 +0000
+++ b/mbed.bld	Fri Sep 20 07:09:28 2019 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/mbed_official/code/mbed/builds/d1b4690b3f8b
\ No newline at end of file
+https://os.mbed.com/users/mbed_official/code/mbed/builds/675da3299148
\ No newline at end of file