Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FXOS8700Q FastPWM

Committer:
MatthewMaat
Date:
Wed Sep 11 09:58:25 2019 +0000
Revision:
5:cee5f898b350
Parent:
4:f988679bf9a1
Child:
7:a32766b96d91
Pick color with interrupt

Who changed what in which revision?

UserRevisionLine numberNew 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>
MatthewMaat 5:cee5f898b350 8 MODSERIAL pc(USBTX, USBRX);
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 5:cee5f898b350 13
MatthewMaat 4:f988679bf9a1 14
RobertoO 0:67c50348f842 15
MatthewMaat 3:46c11151e0fd 16 Ticker Theticker;
MatthewMaat 3:46c11151e0fd 17 volatile char c='x';
MatthewMaat 5:cee5f898b350 18 volatile int color=0;
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 5:cee5f898b350 53 else if (c=='d')
MatthewMaat 5:cee5f898b350 54 {
MatthewMaat 5:cee5f898b350 55 color+=1;
MatthewMaat 5:cee5f898b350 56 ledred=!ledred;
MatthewMaat 5:cee5f898b350 57 if (color%2==0)
MatthewMaat 5:cee5f898b350 58 {
MatthewMaat 5:cee5f898b350 59 ledgreen=!ledgreen;
MatthewMaat 5:cee5f898b350 60 }
MatthewMaat 5:cee5f898b350 61 if (color%4==0)
MatthewMaat 5:cee5f898b350 62 {
MatthewMaat 5:cee5f898b350 63 ledblue=!ledblue;
MatthewMaat 5:cee5f898b350 64 }
MatthewMaat 5:cee5f898b350 65 }
MatthewMaat 3:46c11151e0fd 66 else
MatthewMaat 3:46c11151e0fd 67 {
MatthewMaat 3:46c11151e0fd 68 ledred=1;
MatthewMaat 3:46c11151e0fd 69 ledgreen=1;
MatthewMaat 3:46c11151e0fd 70 ledblue=1;
MatthewMaat 3:46c11151e0fd 71 }
MatthewMaat 3:46c11151e0fd 72 }
RobertoO 0:67c50348f842 73
RobertoO 0:67c50348f842 74 int main()
RobertoO 0:67c50348f842 75 {
MatthewMaat 5:cee5f898b350 76 button.fall(&PrintColor);
MatthewMaat 3:46c11151e0fd 77 ledred=1;
MatthewMaat 3:46c11151e0fd 78 ledgreen=1;
MatthewMaat 3:46c11151e0fd 79 ledblue=1;
MatthewMaat 3:46c11151e0fd 80 Theticker.attach(Take_Measurement,0.05);
MatthewMaat 3:46c11151e0fd 81 int countr;
RobertoO 0:67c50348f842 82 pc.baud(115200);
RobertoO 1:b862262a9d14 83 pc.printf("\r\nStarting...\r\n\r\n");
MatthewMaat 3:46c11151e0fd 84 pc.printf("Enter the color that has to blink:\r\n");
MatthewMaat 3:46c11151e0fd 85 c=pc.getc();
MatthewMaat 3:46c11151e0fd 86 pc.printf("Color picked: '%c'\r\nNow counting so the system does something:\r\n",c);
RobertoO 0:67c50348f842 87 while (true) {
MatthewMaat 5:cee5f898b350 88 countr+=1;
MatthewMaat 3:46c11151e0fd 89 pc.printf("%i\r\n",countr);
RobertoO 0:67c50348f842 90 wait_ms(500);
RobertoO 0:67c50348f842 91 }
RobertoO 0:67c50348f842 92 }