Simplest HIDScope test

Dependencies:   HIDScope mbed QEI

Fork of HID_scope_test by Sjoerd Barts

Committer:
sjoerdbarts
Date:
Fri Oct 07 12:06:16 2016 +0000
Revision:
5:36788b154e25
Parent:
3:ce0f979f15fb
Initial working code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sjoerdbarts 0:1883abafaa19 1 #include "mbed.h"
sjoerdbarts 2:5fce9d33997f 2 #include "HIDScope.h"
sjoerdbarts 5:36788b154e25 3 #include "QEI.h"
sjoerdbarts 3:ce0f979f15fb 4 #define SERIAL_BAUD 115200 // baud rate for serial communication
sjoerdbarts 3:ce0f979f15fb 5
sjoerdbarts 5:36788b154e25 6 Serial pc(USBTX,USBRX);
sjoerdbarts 3:ce0f979f15fb 7
sjoerdbarts 5:36788b154e25 8 int countsCW = 0;
sjoerdbarts 5:36788b154e25 9 int countsCCW = 0;
sjoerdbarts 5:36788b154e25 10 int net_counts = 0;
sjoerdbarts 5:36788b154e25 11 float degrees = 0.0;
sjoerdbarts 5:36788b154e25 12 const float counts_per_rev = 4200.0;
sjoerdbarts 5:36788b154e25 13 QEI EncoderCW(D12,D13,NC,32);
sjoerdbarts 5:36788b154e25 14 QEI EncoderCCW(D13,D12,NC,32);
sjoerdbarts 0:1883abafaa19 15
sjoerdbarts 5:36788b154e25 16 void PrintDegrees(){
sjoerdbarts 5:36788b154e25 17 pc.printf("\r\n Nett Pulses %i \r\n", net_counts);
sjoerdbarts 5:36788b154e25 18 pc.printf("\r\n Output degrees %f \r\n", degrees);
sjoerdbarts 5:36788b154e25 19 }
sjoerdbarts 5:36788b154e25 20
sjoerdbarts 0:1883abafaa19 21 int main()
sjoerdbarts 0:1883abafaa19 22 {
sjoerdbarts 3:ce0f979f15fb 23 pc.baud(SERIAL_BAUD);
sjoerdbarts 3:ce0f979f15fb 24 pc.printf("\r\n ***THERMONUCLEAR WARFARE COMMENCES*** \r\n");
sjoerdbarts 3:ce0f979f15fb 25
sjoerdbarts 5:36788b154e25 26 // Set ticker for serial communication of counts and degrees
sjoerdbarts 5:36788b154e25 27 Ticker PrintDegreesTicker;
sjoerdbarts 5:36788b154e25 28 PrintDegreesTicker.attach(&PrintDegrees,0.1);
sjoerdbarts 2:5fce9d33997f 29
sjoerdbarts 5:36788b154e25 30 // count the CW and CCW counts and calculate the output degrees
sjoerdbarts 5:36788b154e25 31 while(true){
sjoerdbarts 5:36788b154e25 32 countsCW = EncoderCW.getPulses();
sjoerdbarts 5:36788b154e25 33 countsCCW= EncoderCCW.getPulses();
sjoerdbarts 5:36788b154e25 34 net_counts=countsCW-countsCCW;
sjoerdbarts 5:36788b154e25 35 degrees=(net_counts*360.0)/counts_per_rev;
sjoerdbarts 5:36788b154e25 36
sjoerdbarts 5:36788b154e25 37 }
sjoerdbarts 0:1883abafaa19 38 }