met printstatements 1
Dependencies: HIDScope MODSERIAL PID QEI biquadFilter mbed
Fork of EMG_5 by
Diff: main.cpp
- Revision:
- 8:8a17f65622b4
- Parent:
- 7:3396c3e33928
- Child:
- 9:d33e7b175ad7
--- a/main.cpp Wed Sep 10 04:59:25 2014 +0000 +++ b/main.cpp Wed Sep 10 05:05:59 2014 +0000 @@ -4,8 +4,8 @@ //Define objects AnalogIn emg0(PTB1); //Analog input PwmOut red(LED_RED); //PWM output -Ticker timer; -MODSERIAL pc(USBTX,USBRX,64,1024); +Ticker log_timer; +MODSERIAL pc(USBTX,USBRX); /** Looper function * functions used for Ticker and Timeout should be of type void <name>(void) @@ -16,21 +16,22 @@ * To make a variable global, define it under the includes. * variables that are changed in the interrupt routine (written to) should be made * 'volatile' to let the compiler know that those values may change outside the current context. -* i.e.: "volatile float emg_value;" instead of "float emg_value" +* i.e.: "volatile uint16_t emg_value;" instead of "uint16_t emg_value" * in the example below, the variable is not re-used in the main function, and is thus declared * local in the looper function only. **/ void looper() { /*variable to store value in*/ - float emg_value; + uint16_t emg_value; /*put raw emg value both in red and in emg_value*/ - red = emg_value = emg0.read(); - /*send value to PC. use 6 digits after decimal sign*/ + red = emg0.read(); // read float value (0..1 = 0..3.3V) + emg_value = emg0.read_u16(); // read direct ADC result (0..4096 = 0..3.3V) + /*send value to PC. Line below is used to prevent buffer overrun */ if(pc.rxBufferGetSize(0)-pc.rxBufferGetCount() > 30) - pc.printf("%.6f\n",emg_value); + pc.printf("%u\n",emg_value); /**When not using the LED, the above could also have been done this way: - * pc.printf("%.6\n", emg0.read()); + * pc.printf("%u\n", emg0.read_u16()); */ } @@ -41,10 +42,10 @@ /*set the period for the PWM to the red LED*/ red.period_ms(2); /**Here you attach the 'void looper(void)' function to the Ticker object - * The looper() function will be called every 0.001 seconds. + * The looper() function will be called every 0.002 seconds. * Please mind that the parentheses after looper are omitted when using attach. */ - timer.attach(looper, 0.005); + log_timer.attach(looper, 0.01); while(1) //Loop { /*Empty!*/