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 8:0067469c3389, committed 2017-09-19
- Comitter:
- tvlogman
- Date:
- Tue Sep 19 14:50:53 2017 +0000
- Parent:
- 7:1bffab95fc5f
- Child:
- 9:5f0e796c9489
- Commit message:
- Using Hidscope to read LED brightness - not screwed up (yet)
Changed in this revision
| HIDScope.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 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HIDScope.lib Tue Sep 19 14:50:53 2017 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/tomlankhorst/code/HIDScope/#d23c6edecc49
--- a/main.cpp Tue Sep 19 14:17:30 2017 +0000
+++ b/main.cpp Tue Sep 19 14:50:53 2017 +0000
@@ -1,11 +1,35 @@
#include "mbed.h"
#include "MODSERIAL.h"
+#include "HIDScope.h"
+
+HIDScope scope(2);
+
+Ticker AInTicker;
+AnalogIn aIn1(A0);
+
+volatile float x;
+volatile float x_prev =0;
+volatile float y; // filtered 'output' of ReadAnalogInAndFilter
+volatile float ledBrightness = 0.00;
+
+void ReadAnalogInAndFilter()
+{
+ x = ledBrightness; // 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 button(D3);
+DigitalIn button1(D3);
+DigitalIn button2(D6);
+
MODSERIAL pc(USBTX, USBRX);
@@ -14,18 +38,23 @@
{
pc.baud(115200);
- pc.printf("Hello World!\r\n");
-
+ AInTicker.attach(&ReadAnalogInAndFilter, 0.01);
ledPwm.period(pwmPeriod);
-
while (true) {
- float potMeterValue = pot.read();
- ledPwm = potMeterValue;
+ if(!button1){
+ if(ledBrightness >= 0.05){
+ ledBrightness = ledBrightness - 0.05;
+ }
+ }
+ if(!button2){
+ if(ledBrightness <= 0.95){
+ ledBrightness = ledBrightness + 0.05;
+ }
+ }
+ ledPwm = ledBrightness;
wait(0.1f);
-
-
}
}
