Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FastPWM HIDScope MODSERIAL QEI Matrix biquadFilter controller errorFetch mbed motorConfig refGen MatrixMath inverseKinematics
Fork of Minor_test_serial by
Revision 10:e23cbcdde7e3, committed 2017-09-21
- Comitter:
- tvlogman
- Date:
- Thu Sep 21 08:12:58 2017 +0000
- Parent:
- 9:5f0e796c9489
- Child:
- 11:d1692be2de30
- Commit message:
- With encoder reading - not doing anything just yet;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Sep 19 15:25:42 2017 +0000
+++ b/main.cpp Thu Sep 21 08:12:58 2017 +0000
@@ -3,54 +3,24 @@
#include "HIDScope.h"
#include "QEI.h"
+QEI Encoder(D12,D13,NC,32);
HIDScope scope(2);
-
-Ticker AInTicker;
-AnalogIn button1(A4);
-
-volatile float x;
-volatile float x_prev =0;
-volatile float y; // filtered 'output' of ReadAnalogInAndFilter
-volatile float ledBrightness = 0.00;
+MODSERIAL pc(USBTX, USBRX);
-void ReadAnalogInAndFilter()
-{
- x = button1; // Capture data
- scope.set(0, x); // store data in first element of scope memory
- y = (x_prev + x)/2.0; // averaging filter
- scope.set(1, y); // store data in second element of scope memory
- x_prev = x; // Prepare for next round
-
- scope.send(); // send what's in scope memory to PC
-}
-
-PwmOut ledPwm(D5);
-float pwmPeriod = 1.0/5000.0;
-
-AnalogIn pot(A5);
-
-DigitalIn button2(D6);
+Ticker encoderTicker;
+volatile int counts = 0;
-MODSERIAL pc(USBTX, USBRX);
+void readEncoder(){
+ counts = Encoder.getPulses();
+ pc.printf("%i pulses", counts);
+ }
int main()
-{
-
+ {
pc.baud(115200);
- AInTicker.attach(&ReadAnalogInAndFilter, 0.01);
- ledPwm.period(pwmPeriod);
- pc.printf("Hello world");
- int counts;
-
- QEI Encoder(D12,D13,NC,32);
-
- while (true) {
- counts = Encoder.getPulses();
- pc.printf("Number of pulses is %i", counts);
- wait(0.5);
-
+ pc.printf("Encoder ticker attached and baudrate set");
+ encoderTicker.attach(readEncoder, 2.0);
}
-}
