Demo Day SSL using 3 microphones and KL25z
Dependencies: Multi_WS2811_Mic FastAnalogIn USBDevice mbed
main.cpp@2:3d06dcc44f2a, 2014-12-09 (annotated)
- Committer:
- antoniorohit
- Date:
- Tue Dec 09 23:43:24 2014 +0000
- Revision:
- 2:3d06dcc44f2a
- Parent:
- 1:56a68eaa1129
first rev;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
antoniorohit | 0:5cb897285e00 | 1 | #include "mbed.h" |
antoniorohit | 0:5cb897285e00 | 2 | #include "FastAnalogIn.h" |
antoniorohit | 1:56a68eaa1129 | 3 | #include "WS2811.h" |
antoniorohit | 1:56a68eaa1129 | 4 | #include "Colors.h" |
antoniorohit | 1:56a68eaa1129 | 5 | |
antoniorohit | 1:56a68eaa1129 | 6 | unsigned const nLEDs = 30;//MAX_LEDS_PER_STRIP; |
antoniorohit | 1:56a68eaa1129 | 7 | unsigned const DATA_OUT_PIN1 = 7; // PTC7 |
antoniorohit | 1:56a68eaa1129 | 8 | |
antoniorohit | 1:56a68eaa1129 | 9 | FastAnalogIn mic0(A0, 0); |
antoniorohit | 1:56a68eaa1129 | 10 | FastAnalogIn mic1(A1, 0); |
antoniorohit | 1:56a68eaa1129 | 11 | FastAnalogIn mic2(A2, 0); |
antoniorohit | 1:56a68eaa1129 | 12 | Serial pc(USBTX, USBRX); |
antoniorohit | 1:56a68eaa1129 | 13 | |
antoniorohit | 1:56a68eaa1129 | 14 | DigitalOut ledR(LED_RED); |
antoniorohit | 1:56a68eaa1129 | 15 | DigitalOut ledG(LED_GREEN); |
antoniorohit | 1:56a68eaa1129 | 16 | DigitalOut ledB(LED_BLUE); |
antoniorohit | 0:5cb897285e00 | 17 | |
antoniorohit | 1:56a68eaa1129 | 18 | static void showSolidColor(WS2811 &strip, uint8_t r, uint8_t g, uint8_t b) |
antoniorohit | 1:56a68eaa1129 | 19 | { |
antoniorohit | 1:56a68eaa1129 | 20 | unsigned nLEDs = strip.numPixels(); |
antoniorohit | 1:56a68eaa1129 | 21 | for (unsigned i = 0; i < nLEDs; i++) { |
antoniorohit | 1:56a68eaa1129 | 22 | strip.setPixelColor(i, r, g, b); |
antoniorohit | 1:56a68eaa1129 | 23 | } |
antoniorohit | 1:56a68eaa1129 | 24 | strip.show(); |
antoniorohit | 1:56a68eaa1129 | 25 | } |
antoniorohit | 1:56a68eaa1129 | 26 | |
antoniorohit | 1:56a68eaa1129 | 27 | static void clearScreen(WS2811 &strip) |
antoniorohit | 1:56a68eaa1129 | 28 | { |
antoniorohit | 1:56a68eaa1129 | 29 | unsigned nLEDs = strip.numPixels(); |
antoniorohit | 1:56a68eaa1129 | 30 | for (unsigned i = 0; i < nLEDs; i++) { |
antoniorohit | 1:56a68eaa1129 | 31 | strip.setPixelColor(i, 0, 0, 0); |
antoniorohit | 1:56a68eaa1129 | 32 | } |
antoniorohit | 1:56a68eaa1129 | 33 | strip.show(); |
antoniorohit | 1:56a68eaa1129 | 34 | } |
antoniorohit | 0:5cb897285e00 | 35 | |
antoniorohit | 0:5cb897285e00 | 36 | int main(void) { |
antoniorohit | 0:5cb897285e00 | 37 | uint16_t i = 0; |
antoniorohit | 1:56a68eaa1129 | 38 | uint16_t buff0[500]; |
antoniorohit | 1:56a68eaa1129 | 39 | uint16_t buff1[500]; |
antoniorohit | 1:56a68eaa1129 | 40 | uint16_t buff2[500]; |
antoniorohit | 1:56a68eaa1129 | 41 | char pc_read = 0; |
antoniorohit | 1:56a68eaa1129 | 42 | pc.baud(921600); |
antoniorohit | 1:56a68eaa1129 | 43 | ledR = ledG = ledB = 1; |
antoniorohit | 1:56a68eaa1129 | 44 | WS2811 lightStrip1(nLEDs, DATA_OUT_PIN1); |
antoniorohit | 1:56a68eaa1129 | 45 | lightStrip1.begin(); |
antoniorohit | 1:56a68eaa1129 | 46 | |
antoniorohit | 0:5cb897285e00 | 47 | while (true){ |
antoniorohit | 1:56a68eaa1129 | 48 | pc_read = 0; |
antoniorohit | 1:56a68eaa1129 | 49 | for(i = 0; i < 251; i++){ |
antoniorohit | 1:56a68eaa1129 | 50 | buff0[i] = int(1000*mic0.read()); |
antoniorohit | 1:56a68eaa1129 | 51 | buff1[i] = int(1000*mic1.read()); |
antoniorohit | 1:56a68eaa1129 | 52 | buff2[i] = int(1000*mic2.read()); |
antoniorohit | 1:56a68eaa1129 | 53 | } |
antoniorohit | 1:56a68eaa1129 | 54 | for(i = 0; i < 251; i++){ |
antoniorohit | 1:56a68eaa1129 | 55 | pc.printf("%d,%d,%d\n", buff0[i], buff1[i], buff2[i]); |
antoniorohit | 1:56a68eaa1129 | 56 | } |
antoniorohit | 1:56a68eaa1129 | 57 | |
antoniorohit | 1:56a68eaa1129 | 58 | while(pc_read != 'Y'){ |
antoniorohit | 1:56a68eaa1129 | 59 | while(!pc.readable()); |
antoniorohit | 1:56a68eaa1129 | 60 | pc_read = pc.getc(); |
antoniorohit | 1:56a68eaa1129 | 61 | switch(pc_read){ |
antoniorohit | 1:56a68eaa1129 | 62 | case 'Y': |
antoniorohit | 1:56a68eaa1129 | 63 | pc.printf("Go\n"); |
antoniorohit | 1:56a68eaa1129 | 64 | break; |
antoniorohit | 1:56a68eaa1129 | 65 | |
antoniorohit | 1:56a68eaa1129 | 66 | case 'R': |
antoniorohit | 1:56a68eaa1129 | 67 | ledR = 0; |
antoniorohit | 1:56a68eaa1129 | 68 | ledG = 1; |
antoniorohit | 1:56a68eaa1129 | 69 | ledB = 1; |
antoniorohit | 1:56a68eaa1129 | 70 | break; |
antoniorohit | 1:56a68eaa1129 | 71 | |
antoniorohit | 1:56a68eaa1129 | 72 | case 'G': |
antoniorohit | 1:56a68eaa1129 | 73 | ledR = 1; |
antoniorohit | 1:56a68eaa1129 | 74 | ledG = 0; |
antoniorohit | 1:56a68eaa1129 | 75 | ledB = 1; |
antoniorohit | 1:56a68eaa1129 | 76 | break; |
antoniorohit | 0:5cb897285e00 | 77 | |
antoniorohit | 1:56a68eaa1129 | 78 | case 'B': |
antoniorohit | 1:56a68eaa1129 | 79 | ledR = 1; |
antoniorohit | 1:56a68eaa1129 | 80 | ledG = 1; |
antoniorohit | 1:56a68eaa1129 | 81 | ledB = 0; |
antoniorohit | 1:56a68eaa1129 | 82 | break; |
antoniorohit | 1:56a68eaa1129 | 83 | |
antoniorohit | 1:56a68eaa1129 | 84 | case '1': |
antoniorohit | 1:56a68eaa1129 | 85 | clearScreen(lightStrip1); |
antoniorohit | 1:56a68eaa1129 | 86 | lightStrip1.setPixelColor(0, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 87 | lightStrip1.setPixelColor(1, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 88 | lightStrip1.setPixelColor(2, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 89 | lightStrip1.setPixelColor(3, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 90 | lightStrip1.setPixelColor(4, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 91 | break; |
antoniorohit | 1:56a68eaa1129 | 92 | |
antoniorohit | 1:56a68eaa1129 | 93 | case '2': |
antoniorohit | 1:56a68eaa1129 | 94 | clearScreen(lightStrip1); |
antoniorohit | 1:56a68eaa1129 | 95 | lightStrip1.setPixelColor(5, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 96 | lightStrip1.setPixelColor(6, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 97 | lightStrip1.setPixelColor(7, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 98 | lightStrip1.setPixelColor(8, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 99 | lightStrip1.setPixelColor(9, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 100 | break; |
antoniorohit | 1:56a68eaa1129 | 101 | |
antoniorohit | 1:56a68eaa1129 | 102 | case '3': |
antoniorohit | 1:56a68eaa1129 | 103 | clearScreen(lightStrip1); |
antoniorohit | 1:56a68eaa1129 | 104 | lightStrip1.setPixelColor(10, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 105 | lightStrip1.setPixelColor(11, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 106 | lightStrip1.setPixelColor(12, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 107 | lightStrip1.setPixelColor(13, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 108 | lightStrip1.setPixelColor(14, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 109 | break; |
antoniorohit | 1:56a68eaa1129 | 110 | |
antoniorohit | 1:56a68eaa1129 | 111 | case '4': |
antoniorohit | 1:56a68eaa1129 | 112 | clearScreen(lightStrip1); |
antoniorohit | 1:56a68eaa1129 | 113 | lightStrip1.setPixelColor(15, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 114 | lightStrip1.setPixelColor(16, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 115 | lightStrip1.setPixelColor(17, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 116 | lightStrip1.setPixelColor(18, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 117 | lightStrip1.setPixelColor(19, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 118 | break; |
antoniorohit | 1:56a68eaa1129 | 119 | |
antoniorohit | 1:56a68eaa1129 | 120 | case '5': |
antoniorohit | 1:56a68eaa1129 | 121 | clearScreen(lightStrip1); |
antoniorohit | 1:56a68eaa1129 | 122 | lightStrip1.setPixelColor(20, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 123 | lightStrip1.setPixelColor(21, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 124 | lightStrip1.setPixelColor(22, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 125 | lightStrip1.setPixelColor(23, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 126 | lightStrip1.setPixelColor(24, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 127 | break; |
antoniorohit | 1:56a68eaa1129 | 128 | |
antoniorohit | 1:56a68eaa1129 | 129 | case '6': |
antoniorohit | 1:56a68eaa1129 | 130 | clearScreen(lightStrip1); |
antoniorohit | 1:56a68eaa1129 | 131 | lightStrip1.setPixelColor(25, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 132 | lightStrip1.setPixelColor(26, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 133 | lightStrip1.setPixelColor(27, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 134 | lightStrip1.setPixelColor(28, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 135 | lightStrip1.setPixelColor(29, ledR*100, ledG*100, ledB*100); |
antoniorohit | 1:56a68eaa1129 | 136 | break; |
antoniorohit | 1:56a68eaa1129 | 137 | |
antoniorohit | 1:56a68eaa1129 | 138 | default: |
antoniorohit | 1:56a68eaa1129 | 139 | break; |
antoniorohit | 1:56a68eaa1129 | 140 | |
antoniorohit | 1:56a68eaa1129 | 141 | } |
antoniorohit | 1:56a68eaa1129 | 142 | lightStrip1.show(); |
antoniorohit | 1:56a68eaa1129 | 143 | WS2811::startDMA(); |
antoniorohit | 0:5cb897285e00 | 144 | } |
antoniorohit | 0:5cb897285e00 | 145 | } |
antoniorohit | 0:5cb897285e00 | 146 | } |