mag niet van hendrik D:
Dependencies: mbed MatrixMath QEI HIDScope Matrix biquadFilter MODSERIAL FastPWM
main.cpp@10:3a3d6373b41c, 2019-09-20 (annotated)
- Committer:
- Hendrikvg
- Date:
- Fri Sep 20 07:09:28 2019 +0000
- Revision:
- 10:3a3d6373b41c
- Parent:
- 9:12b9865e7373
- Child:
- 11:008c8060e640
Scope met potentiometer werkt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Hendrikvg | 9:12b9865e7373 | 1 | #include "mbed.h" |
Hendrikvg | 10:3a3d6373b41c | 2 | #include "HIDScope.h" |
Hendrikvg | 9:12b9865e7373 | 3 | |
Hendrikvg | 9:12b9865e7373 | 4 | Serial pc(USBTX,USBRX); |
Hendrikvg | 10:3a3d6373b41c | 5 | HIDScope scope(2); |
Hendrikvg | 10:3a3d6373b41c | 6 | Ticker AInTicker; |
Hendrikvg | 9:12b9865e7373 | 7 | InterruptIn BUT1(D1); |
Hendrikvg | 9:12b9865e7373 | 8 | InterruptIn BUT2(D0); |
Hendrikvg | 9:12b9865e7373 | 9 | PwmOut lichtje(D3); |
Hendrikvg | 9:12b9865e7373 | 10 | AnalogIn ain(A0); |
RobertoO | 0:67c50348f842 | 11 | |
Hendrikvg | 9:12b9865e7373 | 12 | float getal; |
Hendrikvg | 9:12b9865e7373 | 13 | int n=5; |
Hendrikvg | 2:d9b0ebf3fcca | 14 | |
Hendrikvg | 10:3a3d6373b41c | 15 | volatile float x; |
Hendrikvg | 10:3a3d6373b41c | 16 | volatile float x_prev=0; |
Hendrikvg | 10:3a3d6373b41c | 17 | volatile float y; |
Hendrikvg | 10:3a3d6373b41c | 18 | |
Hendrikvg | 10:3a3d6373b41c | 19 | void ReadAnalogInAndFilter() |
Hendrikvg | 10:3a3d6373b41c | 20 | { |
Hendrikvg | 10:3a3d6373b41c | 21 | x = ain; // Capture data |
Hendrikvg | 10:3a3d6373b41c | 22 | scope.set(0, x); // store data in first element of scope memory |
Hendrikvg | 10:3a3d6373b41c | 23 | y = (x_prev+ x)/2.0; // averaging |
Hendrikvg | 10:3a3d6373b41c | 24 | scope.set(1, y);// store data in second element of scope memory filter |
Hendrikvg | 10:3a3d6373b41c | 25 | x_prev= x; // Prepare for next round |
Hendrikvg | 10:3a3d6373b41c | 26 | |
Hendrikvg | 10:3a3d6373b41c | 27 | scope.send(); // send what's in scope memory to PC |
Hendrikvg | 10:3a3d6373b41c | 28 | } |
Hendrikvg | 10:3a3d6373b41c | 29 | |
Hendrikvg | 9:12b9865e7373 | 30 | void plus() |
Hendrikvg | 9:12b9865e7373 | 31 | { |
Hendrikvg | 9:12b9865e7373 | 32 | n++; // n=n+1 |
Hendrikvg | 10:3a3d6373b41c | 33 | if (n>10) { |
Hendrikvg | 9:12b9865e7373 | 34 | n=10; |
Hendrikvg | 9:12b9865e7373 | 35 | } |
Hendrikvg | 10:3a3d6373b41c | 36 | } |
Hendrikvg | 10:3a3d6373b41c | 37 | |
Hendrikvg | 9:12b9865e7373 | 38 | void min() |
Hendrikvg | 8:d1794f225fff | 39 | { |
Hendrikvg | 9:12b9865e7373 | 40 | n--; |
Hendrikvg | 10:3a3d6373b41c | 41 | if (n<0) { |
Hendrikvg | 9:12b9865e7373 | 42 | n=0; |
Hendrikvg | 7:d307e31f7391 | 43 | } |
Hendrikvg | 10:3a3d6373b41c | 44 | } |
Hendrikvg | 7:d307e31f7391 | 45 | |
Hendrikvg | 9:12b9865e7373 | 46 | int main() { |
RobertoO | 0:67c50348f842 | 47 | pc.baud(115200); |
Hendrikvg | 9:12b9865e7373 | 48 | lichtje=1; |
Hendrikvg | 9:12b9865e7373 | 49 | BUT1.fall(plus); |
Hendrikvg | 9:12b9865e7373 | 50 | BUT2.fall(min); |
Hendrikvg | 10:3a3d6373b41c | 51 | AInTicker.attach(&ReadAnalogInAndFilter, 0.01); |
Hendrikvg | 9:12b9865e7373 | 52 | while(true) |
Hendrikvg | 9:12b9865e7373 | 53 | { |
Hendrikvg | 10:3a3d6373b41c | 54 | |
Hendrikvg | 9:12b9865e7373 | 55 | } |
Hendrikvg | 2:d9b0ebf3fcca | 56 | } |