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: mbed QEI HIDScope biquadFilter MODSERIAL FXOS8700Q FastPWM
main.cpp@4:f988679bf9a1, 2019-09-11 (annotated)
- Committer:
- MatthewMaat
- Date:
- Wed Sep 11 09:47:18 2019 +0000
- Revision:
- 4:f988679bf9a1
- Parent:
- 3:46c11151e0fd
- Child:
- 5:cee5f898b350
3c
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| RobertoO | 0:67c50348f842 | 1 | #include "mbed.h" |
| RobertoO | 0:67c50348f842 | 2 | //#include "HIDScope.h" |
| RobertoO | 0:67c50348f842 | 3 | //#include "QEI.h" |
| RobertoO | 1:b862262a9d14 | 4 | #include "MODSERIAL.h" |
| RobertoO | 0:67c50348f842 | 5 | //#include "BiQuad.h" |
| RobertoO | 1:b862262a9d14 | 6 | //#include "FastPWM.h" |
| MatthewMaat | 2:626688c21b6f | 7 | #include <iostream> |
| RobertoO | 0:67c50348f842 | 8 | |
| MatthewMaat | 2:626688c21b6f | 9 | DigitalOut ledred(LED_RED); |
| MatthewMaat | 2:626688c21b6f | 10 | DigitalOut ledblue(LED_BLUE); |
| MatthewMaat | 2:626688c21b6f | 11 | DigitalOut ledgreen(LED_GREEN); |
| MatthewMaat | 4:f988679bf9a1 | 12 | InterruptIn button(SW2); |
| MatthewMaat | 4:f988679bf9a1 | 13 | button.fall(PrintColor); |
| MatthewMaat | 4:f988679bf9a1 | 14 | |
| RobertoO | 0:67c50348f842 | 15 | |
| RobertoO | 1:b862262a9d14 | 16 | MODSERIAL pc(USBTX, USBRX); |
| MatthewMaat | 3:46c11151e0fd | 17 | Ticker Theticker; |
| MatthewMaat | 3:46c11151e0fd | 18 | volatile char c='x'; |
| MatthewMaat | 4:f988679bf9a1 | 19 | void PrintColor(void) |
| MatthewMaat | 4:f988679bf9a1 | 20 | { |
| MatthewMaat | 4:f988679bf9a1 | 21 | switch(c) |
| MatthewMaat | 4:f988679bf9a1 | 22 | { |
| MatthewMaat | 4:f988679bf9a1 | 23 | case 'r': |
| MatthewMaat | 4:f988679bf9a1 | 24 | pc.printf("Red"); |
| MatthewMaat | 4:f988679bf9a1 | 25 | break; |
| MatthewMaat | 4:f988679bf9a1 | 26 | case 'g': |
| MatthewMaat | 4:f988679bf9a1 | 27 | pc.printf("Green"); |
| MatthewMaat | 4:f988679bf9a1 | 28 | break; |
| MatthewMaat | 4:f988679bf9a1 | 29 | case 'b': |
| MatthewMaat | 4:f988679bf9a1 | 30 | pc.printf("Blue"); |
| MatthewMaat | 4:f988679bf9a1 | 31 | break; |
| MatthewMaat | 4:f988679bf9a1 | 32 | case 'd': |
| MatthewMaat | 4:f988679bf9a1 | 33 | pc.printf("Disco"); |
| MatthewMaat | 4:f988679bf9a1 | 34 | break; |
| MatthewMaat | 4:f988679bf9a1 | 35 | default: |
| MatthewMaat | 4:f988679bf9a1 | 36 | pc.printf("Unknown"); |
| MatthewMaat | 4:f988679bf9a1 | 37 | } |
| MatthewMaat | 4:f988679bf9a1 | 38 | } |
| MatthewMaat | 3:46c11151e0fd | 39 | void Take_Measurement(void) |
| MatthewMaat | 3:46c11151e0fd | 40 | { |
| MatthewMaat | 3:46c11151e0fd | 41 | if (c=='r') |
| MatthewMaat | 3:46c11151e0fd | 42 | { |
| MatthewMaat | 3:46c11151e0fd | 43 | ledred=!ledred; |
| MatthewMaat | 3:46c11151e0fd | 44 | } |
| MatthewMaat | 3:46c11151e0fd | 45 | else if (c=='g') |
| MatthewMaat | 3:46c11151e0fd | 46 | { |
| MatthewMaat | 3:46c11151e0fd | 47 | ledgreen=!ledgreen; |
| MatthewMaat | 3:46c11151e0fd | 48 | } |
| MatthewMaat | 3:46c11151e0fd | 49 | else if (c=='b') |
| MatthewMaat | 3:46c11151e0fd | 50 | { |
| MatthewMaat | 3:46c11151e0fd | 51 | ledblue=!ledblue; |
| MatthewMaat | 3:46c11151e0fd | 52 | } |
| MatthewMaat | 3:46c11151e0fd | 53 | else |
| MatthewMaat | 3:46c11151e0fd | 54 | { |
| MatthewMaat | 3:46c11151e0fd | 55 | ledred=1; |
| MatthewMaat | 3:46c11151e0fd | 56 | ledgreen=1; |
| MatthewMaat | 3:46c11151e0fd | 57 | ledblue=1; |
| MatthewMaat | 3:46c11151e0fd | 58 | } |
| MatthewMaat | 3:46c11151e0fd | 59 | } |
| RobertoO | 0:67c50348f842 | 60 | |
| RobertoO | 0:67c50348f842 | 61 | int main() |
| RobertoO | 0:67c50348f842 | 62 | { |
| MatthewMaat | 3:46c11151e0fd | 63 | ledred=1; |
| MatthewMaat | 3:46c11151e0fd | 64 | ledgreen=1; |
| MatthewMaat | 3:46c11151e0fd | 65 | ledblue=1; |
| MatthewMaat | 3:46c11151e0fd | 66 | Theticker.attach(Take_Measurement,0.05); |
| MatthewMaat | 3:46c11151e0fd | 67 | int countr; |
| RobertoO | 0:67c50348f842 | 68 | pc.baud(115200); |
| RobertoO | 1:b862262a9d14 | 69 | pc.printf("\r\nStarting...\r\n\r\n"); |
| MatthewMaat | 3:46c11151e0fd | 70 | pc.printf("Enter the color that has to blink:\r\n"); |
| MatthewMaat | 3:46c11151e0fd | 71 | c=pc.getc(); |
| MatthewMaat | 3:46c11151e0fd | 72 | pc.printf("Color picked: '%c'\r\nNow counting so the system does something:\r\n",c); |
| RobertoO | 0:67c50348f842 | 73 | while (true) { |
| MatthewMaat | 2:626688c21b6f | 74 | color+=1; |
| MatthewMaat | 3:46c11151e0fd | 75 | pc.printf("%i\r\n",countr); |
| RobertoO | 0:67c50348f842 | 76 | wait_ms(500); |
| RobertoO | 0:67c50348f842 | 77 | } |
| RobertoO | 0:67c50348f842 | 78 | } |
