File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,7 +24,6 @@ void Devlpr::tick()
2424 // NOTE do we want to do some sort of remainder on
2525 // NOTE the micros - ie do we want to play catch up
2626 // NOTE or just make a best effort to run on sched?
27- dummy = lastValueFiltered ();
2827 }
2928 // just pretend no time has passed since function start
3029 lastTickMicros = currMicros;
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ class Devlpr
1111 int lastValue ();
1212 float lastValueFiltered ();
1313 float windowAvg ();
14- float dummy;
1514 private:
1615 // general buffer bookkeeping
1716 static const byte BUFSIZE = 155 ; // size of filter
Original file line number Diff line number Diff line change @@ -6,6 +6,25 @@ void setup() {
66 Serial.begin (9600 );
77}
88
9+ unsigned long microsSinceFilteredCall = 0 ;
10+ unsigned long prevLoopMicros = 0 ;
11+ float result = 0.0 ;
912void loop () {
13+ // let the DEVLPR library do its job
1014 devlpr.tick ();
15+
16+ // try to sample filtered data at 1000Hz
17+ unsigned long currMicros = micros ();
18+ unsigned long microsDelta = currMicros - prevLoopMicros;
19+ microsSinceFilteredCall += microsDelta;
20+ // has 1ms passed
21+ if (microsSinceFilteredCall > 1000 ) {
22+ // 1ms has passed, get the value
23+ result = devlpr.lastValueFiltered ();
24+ Serial.println (result);
25+ // update our last filtered call
26+ microsSinceFilteredCall = 0 ;
27+ }
28+ // update our last loop time
29+ prevLoopMicros = currMicros;
1130}
You can’t perform that action at this time.
0 commit comments