FFT and nRF24 transmission / LaserGame 1A
Dependencies: mbed nRF24L01P mbed-dsp
main.cpp@2:76fbb91a0331, 2021-02-09 (annotated)
- Committer:
- villemejane
- Date:
- Tue Feb 09 14:33:50 2021 +0000
- Revision:
- 2:76fbb91a0331
- Parent:
- 0:96c89b4dc711
DMX512 interface - LEnsE / VILLEMEJANE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
villemejane | 2:76fbb91a0331 | 1 | /* mbed Microcontroller Library |
villemejane | 2:76fbb91a0331 | 2 | * Copyright (c) 2019 ARM Limited |
villemejane | 2:76fbb91a0331 | 3 | * SPDX-License-Identifier: Apache-2.0 |
villemejane | 2:76fbb91a0331 | 4 | */ |
villemejane | 0:96c89b4dc711 | 5 | |
villemejane | 2:76fbb91a0331 | 6 | #include "mbed.h" |
villemejane | 2:76fbb91a0331 | 7 | |
villemejane | 2:76fbb91a0331 | 8 | #define SAMPLES 512 |
villemejane | 2:76fbb91a0331 | 9 | Serial debug_pc(USBTX, USBRX); |
villemejane | 0:96c89b4dc711 | 10 | |
villemejane | 2:76fbb91a0331 | 11 | Serial dmx(PC_10, PC_11); |
villemejane | 2:76fbb91a0331 | 12 | DigitalOut out_tx(D10); |
villemejane | 2:76fbb91a0331 | 13 | DigitalOut start(D11); |
villemejane | 2:76fbb91a0331 | 14 | DigitalOut enableDMX(D5); |
villemejane | 2:76fbb91a0331 | 15 | |
villemejane | 2:76fbb91a0331 | 16 | AnalogIn variationR(A0); |
villemejane | 2:76fbb91a0331 | 17 | AnalogIn variationG(A1); |
villemejane | 2:76fbb91a0331 | 18 | AnalogIn variationB(A2); |
villemejane | 2:76fbb91a0331 | 19 | |
villemejane | 2:76fbb91a0331 | 20 | DigitalIn my_bp(USER_BUTTON); |
villemejane | 2:76fbb91a0331 | 21 | |
villemejane | 2:76fbb91a0331 | 22 | char dmx_data[SAMPLES] = {0}; |
villemejane | 2:76fbb91a0331 | 23 | char nb = 0; |
villemejane | 2:76fbb91a0331 | 24 | |
villemejane | 2:76fbb91a0331 | 25 | void dmx_update(); |
villemejane | 2:76fbb91a0331 | 26 | |
villemejane | 0:96c89b4dc711 | 27 | int main() { |
villemejane | 2:76fbb91a0331 | 28 | debug_pc.baud(9600); |
villemejane | 2:76fbb91a0331 | 29 | debug_pc.printf("Essai DMX512\r\n"); |
villemejane | 2:76fbb91a0331 | 30 | dmx.baud(250000); |
villemejane | 2:76fbb91a0331 | 31 | dmx.format (8, SerialBase::None, 2); |
villemejane | 2:76fbb91a0331 | 32 | enableDMX = 0; |
villemejane | 2:76fbb91a0331 | 33 | |
villemejane | 2:76fbb91a0331 | 34 | // Eurolite LED H2O - 5 channels / adress 0 |
villemejane | 2:76fbb91a0331 | 35 | dmx_data[0] = 0x00; // Red |
villemejane | 2:76fbb91a0331 | 36 | dmx_data[1] = 0x00; // Green |
villemejane | 2:76fbb91a0331 | 37 | dmx_data[2] = 0x00; // Blue |
villemejane | 2:76fbb91a0331 | 38 | dmx_data[3] = 0xFF; // Dimmer - Max = 255 |
villemejane | 2:76fbb91a0331 | 39 | dmx_data[4] = 0x00; // On = 0 |
villemejane | 2:76fbb91a0331 | 40 | |
villemejane | 0:96c89b4dc711 | 41 | while(1) { |
villemejane | 2:76fbb91a0331 | 42 | int valeur = variationR.read_u16() >> 8; |
villemejane | 2:76fbb91a0331 | 43 | dmx_data[0] = valeur; |
villemejane | 2:76fbb91a0331 | 44 | valeur = variationG.read_u16() >> 8; |
villemejane | 2:76fbb91a0331 | 45 | dmx_data[1] = valeur; |
villemejane | 2:76fbb91a0331 | 46 | valeur = variationB.read_u16() >> 8; |
villemejane | 2:76fbb91a0331 | 47 | dmx_data[2] = valeur; |
villemejane | 2:76fbb91a0331 | 48 | dmx_data[4] = 0; // on |
villemejane | 2:76fbb91a0331 | 49 | dmx_update(); |
villemejane | 2:76fbb91a0331 | 50 | wait_us(100000); |
villemejane | 2:76fbb91a0331 | 51 | } |
villemejane | 2:76fbb91a0331 | 52 | } |
villemejane | 2:76fbb91a0331 | 53 | |
villemejane | 2:76fbb91a0331 | 54 | |
villemejane | 2:76fbb91a0331 | 55 | void dmx_update(){ |
villemejane | 2:76fbb91a0331 | 56 | enableDMX = 1; |
villemejane | 2:76fbb91a0331 | 57 | start = 1; // /start |
villemejane | 2:76fbb91a0331 | 58 | out_tx = 0; // break |
villemejane | 2:76fbb91a0331 | 59 | wait_us(88); |
villemejane | 2:76fbb91a0331 | 60 | out_tx = 1; // mb |
villemejane | 2:76fbb91a0331 | 61 | wait_us(8); |
villemejane | 2:76fbb91a0331 | 62 | out_tx = 0; // break |
villemejane | 2:76fbb91a0331 | 63 | start = 0; |
villemejane | 2:76fbb91a0331 | 64 | dmx.putc(0x00); // Start |
villemejane | 2:76fbb91a0331 | 65 | for(int i = 0; i < SAMPLES; i++){ |
villemejane | 2:76fbb91a0331 | 66 | dmx.putc(dmx_data[i]); // data |
villemejane | 0:96c89b4dc711 | 67 | } |
villemejane | 2:76fbb91a0331 | 68 | wait_us(23000); // time between frame |
villemejane | 0:96c89b4dc711 | 69 | } |