BioRobotics Group 3 / Mbed 2 deprecated Moving-average

Dependencies:   HIDScope MODSERIAL mbed

Fork of Signal Filter by BioRobotics Group 3

Committer:
Peasofcake
Date:
Wed Sep 09 14:46:35 2015 +0000
Revision:
1:f6110f80fa45
Parent:
0:c8a6e00fbdc3
Child:
2:e30dbfec6d1e
HIDscope

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Peasofcake 0:c8a6e00fbdc3 1 #include "mbed.h"
Peasofcake 1:f6110f80fa45 2 #include "MODSERIAL.h"
Peasofcake 1:f6110f80fa45 3 #include "HIDScope.h"
Peasofcake 1:f6110f80fa45 4
Peasofcake 1:f6110f80fa45 5 DigitalOut r_led(LED_RED);
Peasofcake 1:f6110f80fa45 6 DigitalOut g_led(LED_GREEN);
Peasofcake 1:f6110f80fa45 7 DigitalOut b_led(LED_BLUE);
Peasofcake 1:f6110f80fa45 8
Peasofcake 0:c8a6e00fbdc3 9 DigitalIn button(PTA4);
Peasofcake 1:f6110f80fa45 10 MODSERIAL pc(USBTX, USBRX);
Peasofcake 0:c8a6e00fbdc3 11
Peasofcake 1:f6110f80fa45 12 const int baudrate = 115200;
Peasofcake 1:f6110f80fa45 13 //const int ms_wait = 100;
Peasofcake 0:c8a6e00fbdc3 14
Peasofcake 1:f6110f80fa45 15 // Define the HIDScope and Ticker objects
Peasofcake 1:f6110f80fa45 16 HIDScope scope(2);
Peasofcake 1:f6110f80fa45 17 Ticker scopeTimer;
Peasofcake 1:f6110f80fa45 18 Ticker controllerTimer;
Peasofcake 1:f6110f80fa45 19
Peasofcake 1:f6110f80fa45 20 const float period_led = 0.2;
Peasofcake 1:f6110f80fa45 21 // Two analog inputs to read from
Peasofcake 1:f6110f80fa45 22 AnalogIn a0(p2);
Peasofcake 1:f6110f80fa45 23 AnalogIn a1(p3);
Peasofcake 1:f6110f80fa45 24
Peasofcake 1:f6110f80fa45 25 void controlAndMeasure()
Peasofcake 1:f6110f80fa45 26 {
Peasofcake 1:f6110f80fa45 27 // Do some control
Peasofcake 1:f6110f80fa45 28 // ** control code here **
Peasofcake 1:f6110f80fa45 29
Peasofcake 1:f6110f80fa45 30 // Store values in the scope
Peasofcake 1:f6110f80fa45 31 scope.set(0,a0.read());
Peasofcake 1:f6110f80fa45 32 scope.set(1,a1.read());
Peasofcake 1:f6110f80fa45 33 }
Peasofcake 1:f6110f80fa45 34
Peasofcake 0:c8a6e00fbdc3 35 int main()
Peasofcake 0:c8a6e00fbdc3 36 {
Peasofcake 1:f6110f80fa45 37 // Attach the HIDScope::send method from the scope object to the timer at 50Hz
Peasofcake 1:f6110f80fa45 38 scopeTimer.attach_us(&scope, &HIDScope::send, 2e4);
Peasofcake 1:f6110f80fa45 39
Peasofcake 1:f6110f80fa45 40 // Attach the controlAndMeasure method to the controller timer at 1kHz
Peasofcake 1:f6110f80fa45 41 controllerTimer.attach_us(&controlAndMeasure, 1e3);
Peasofcake 0:c8a6e00fbdc3 42
Peasofcake 1:f6110f80fa45 43 while(1) { }
Peasofcake 1:f6110f80fa45 44
Peasofcake 0:c8a6e00fbdc3 45 }