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: HIDScope MODSERIAL QEI mbed
main.cpp@1:f367ab17bc18, 2015-09-23 (annotated)
- Committer:
- Gerth
- Date:
- Wed Sep 23 13:44:00 2015 +0000
- Revision:
- 1:f367ab17bc18
- Parent:
- 0:3df25d5b2946
- Child:
- 2:04ad19deeb2c
prints value of pot and encoder to hidscope; now make p contoller
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Gerth | 0:3df25d5b2946 | 1 | #include "mbed.h" |
Gerth | 1:f367ab17bc18 | 2 | #include "MODSERIAL.h" |
Gerth | 1:f367ab17bc18 | 3 | #include "QEI.h" |
Gerth | 1:f367ab17bc18 | 4 | #include "HIDScope.h" |
Gerth | 1:f367ab17bc18 | 5 | |
Gerth | 1:f367ab17bc18 | 6 | HIDScope scope(2); |
Gerth | 1:f367ab17bc18 | 7 | MODSERIAL pc(USBTX, USBRX); |
Gerth | 1:f367ab17bc18 | 8 | QEI encoder1 (D13,D12,NC,32); |
Gerth | 1:f367ab17bc18 | 9 | |
Gerth | 1:f367ab17bc18 | 10 | //ingangen |
Gerth | 1:f367ab17bc18 | 11 | AnalogIn pot1(A0); |
Gerth | 1:f367ab17bc18 | 12 | |
Gerth | 1:f367ab17bc18 | 13 | //frequencies |
Gerth | 1:f367ab17bc18 | 14 | const float hidscope_frequency=100; |
Gerth | 1:f367ab17bc18 | 15 | const float p_control_frequency=100; |
Gerth | 1:f367ab17bc18 | 16 | |
Gerth | 1:f367ab17bc18 | 17 | //tickers |
Gerth | 1:f367ab17bc18 | 18 | Ticker hidscope_ticker; |
Gerth | 1:f367ab17bc18 | 19 | Ticker p_control_ticker; |
Gerth | 0:3df25d5b2946 | 20 | |
Gerth | 1:f367ab17bc18 | 21 | //constants |
Gerth | 1:f367ab17bc18 | 22 | const int cpr=32; |
Gerth | 1:f367ab17bc18 | 23 | const float PI=3.1415; |
Gerth | 1:f367ab17bc18 | 24 | const float counttorad=((2*PI)/cpr); |
Gerth | 1:f367ab17bc18 | 25 | |
Gerth | 1:f367ab17bc18 | 26 | //go flags |
Gerth | 1:f367ab17bc18 | 27 | volatile bool scopedata_go=false, p_control_go=false; |
Gerth | 1:f367ab17bc18 | 28 | |
Gerth | 1:f367ab17bc18 | 29 | //acvitator functions |
Gerth | 1:f367ab17bc18 | 30 | |
Gerth | 1:f367ab17bc18 | 31 | void scopedata_activate() |
Gerth | 1:f367ab17bc18 | 32 | { |
Gerth | 1:f367ab17bc18 | 33 | scopedata_go=true; |
Gerth | 1:f367ab17bc18 | 34 | } |
Gerth | 1:f367ab17bc18 | 35 | void p_control_activate(){ |
Gerth | 1:f367ab17bc18 | 36 | p_control_go=true; |
Gerth | 1:f367ab17bc18 | 37 | } |
Gerth | 1:f367ab17bc18 | 38 | ///////////////////////////////////////////////////////FUNCTIONS////////////////////////////////////////////////////////////////////////// |
Gerth | 1:f367ab17bc18 | 39 | |
Gerth | 1:f367ab17bc18 | 40 | //scopedata |
Gerth | 1:f367ab17bc18 | 41 | void scopedata() |
Gerth | 1:f367ab17bc18 | 42 | { |
Gerth | 1:f367ab17bc18 | 43 | scope.set(0,pot1.read()); |
Gerth | 1:f367ab17bc18 | 44 | scope.set(1,counttorad*encoder1.getPulses()); |
Gerth | 1:f367ab17bc18 | 45 | scope.send(); |
Gerth | 1:f367ab17bc18 | 46 | } |
Gerth | 1:f367ab17bc18 | 47 | void p_control(){} |
Gerth | 0:3df25d5b2946 | 48 | |
Gerth | 0:3df25d5b2946 | 49 | int main() |
Gerth | 0:3df25d5b2946 | 50 | { |
Gerth | 1:f367ab17bc18 | 51 | //set initial shizzle |
Gerth | 1:f367ab17bc18 | 52 | |
Gerth | 1:f367ab17bc18 | 53 | |
Gerth | 1:f367ab17bc18 | 54 | //tickers |
Gerth | 1:f367ab17bc18 | 55 | hidscope_ticker.attach(&scopedata_activate,1.0/hidscope_frequency); |
Gerth | 1:f367ab17bc18 | 56 | p_control_ticker.attach(&p_control_activate,1.0/p_control_frequency); |
Gerth | 1:f367ab17bc18 | 57 | |
Gerth | 1:f367ab17bc18 | 58 | while(1) { |
Gerth | 1:f367ab17bc18 | 59 | if (p_control_go==true) { |
Gerth | 1:f367ab17bc18 | 60 | p_control(); |
Gerth | 1:f367ab17bc18 | 61 | p_control_go=false; |
Gerth | 1:f367ab17bc18 | 62 | } |
Gerth | 1:f367ab17bc18 | 63 | if (scopedata_go==true) { |
Gerth | 1:f367ab17bc18 | 64 | scopedata(); |
Gerth | 1:f367ab17bc18 | 65 | scopedata_go=false; |
Gerth | 1:f367ab17bc18 | 66 | } |
Gerth | 0:3df25d5b2946 | 67 | } |
Gerth | 1:f367ab17bc18 | 68 | } |