Simplest HIDScope test
Dependencies: HIDScope mbed QEI
Fork of HID_scope_test by
Revision 5:36788b154e25, committed 2016-10-07
- Comitter:
- sjoerdbarts
- Date:
- Fri Oct 07 12:06:16 2016 +0000
- Parent:
- 4:4f471e508986
- Commit message:
- Initial working code
Changed in this revision
QEI.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 4f471e508986 -r 36788b154e25 QEI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QEI.lib Fri Oct 07 12:06:16 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/aberk/code/QEI/#5c2ad81551aa
diff -r 4f471e508986 -r 36788b154e25 main.cpp --- a/main.cpp Fri Oct 07 09:15:29 2016 +0000 +++ b/main.cpp Fri Oct 07 12:06:16 2016 +0000 @@ -1,57 +1,38 @@ #include "mbed.h" #include "HIDScope.h" +#include "QEI.h" #define SERIAL_BAUD 115200 // baud rate for serial communication - Serial pc(USBTX,USBRX); - -// Define the HIDScope and Ticker object -HIDScope scope(1); -Ticker scopeTimer; - -// Read the analog input -AnalogIn a0(A0); -// AnalogIn pot(A0); - -// Set LED out -DigitalOut led(LED_RED); -volatile int i = 0; +Serial pc(USBTX,USBRX); - -const float kTimeLedToggle = .5f; // period of blinking -const int kLedOn=0; // Led on if 0 -volatile float pot = 0.0; - -// The data read and send function -void scopeSend() -{ - i=i+a0.read(); - - if (i > 100){ - i=0; - } - // pot = a0.read(); - scope.set(0, i); - scope.send(); - pc.printf("\r\n b \r\n"); - pc.printf("\r\n %f \r\n",i); -} +int countsCW = 0; +int countsCCW = 0; +int net_counts = 0; +float degrees = 0.0; +const float counts_per_rev = 4200.0; +QEI EncoderCW(D12,D13,NC,32); +QEI EncoderCCW(D13,D12,NC,32); -void SwitchLed(){ - led = not led; -} - +void PrintDegrees(){ + pc.printf("\r\n Nett Pulses %i \r\n", net_counts); + pc.printf("\r\n Output degrees %f \r\n", degrees); + } + int main() { pc.baud(SERIAL_BAUD); pc.printf("\r\n ***THERMONUCLEAR WARFARE COMMENCES*** \r\n"); - led = not kLedOn; - // Create ticker for LED and attach - Ticker tick_toggle_led; - tick_toggle_led.attach(SwitchLed,kTimeLedToggle); + // Set ticker for serial communication of counts and degrees + Ticker PrintDegreesTicker; + PrintDegreesTicker.attach(&PrintDegrees,0.1); - // Attach the data read and send function at 100 Hz - scopeTimer.attach(&scopeSend, 0.01f); - - while(true); + // count the CW and CCW counts and calculate the output degrees + while(true){ + countsCW = EncoderCW.getPulses(); + countsCCW= EncoderCCW.getPulses(); + net_counts=countsCW-countsCCW; + degrees=(net_counts*360.0)/counts_per_rev; + + } } \ No newline at end of file