DMX512 interface - LEnsE / VILLEMEJANE

Dependencies:   mbed mbed-dsp

main.cpp

Committer:
villemejane
Date:
8 months ago
Revision:
1:76fbb91a0331
Parent:
0:96c89b4dc711

File content as of revision 1:76fbb91a0331:

/* mbed Microcontroller Library
 * Copyright (c) 2019 ARM Limited
 * SPDX-License-Identifier: Apache-2.0
 */

#include "mbed.h"

#define SAMPLES     512 
Serial      debug_pc(USBTX, USBRX);

Serial      dmx(PC_10, PC_11);
DigitalOut  out_tx(D10);
DigitalOut  start(D11);
DigitalOut  enableDMX(D5);

AnalogIn    variationR(A0);
AnalogIn    variationG(A1);
AnalogIn    variationB(A2);

DigitalIn   my_bp(USER_BUTTON);

char dmx_data[SAMPLES] = {0};
char nb = 0;

void dmx_update();

int main() {
    debug_pc.baud(9600);
    debug_pc.printf("Essai DMX512\r\n");
    dmx.baud(250000);
    dmx.format (8, SerialBase::None, 2);
    enableDMX = 0;
    
    // Eurolite LED H2O - 5 channels / adress 0
    dmx_data[0] = 0x00;     // Red
    dmx_data[1] = 0x00;     // Green
    dmx_data[2] = 0x00;     // Blue
    dmx_data[3] = 0xFF;     // Dimmer - Max = 255
    dmx_data[4] = 0x00;     // On = 0
    
    while(1) {
        int valeur = variationR.read_u16() >> 8;
        dmx_data[0] = valeur;  
        valeur = variationG.read_u16() >> 8;
        dmx_data[1] = valeur;
        valeur = variationB.read_u16() >> 8;
        dmx_data[2] = valeur;    
        dmx_data[4] = 0;    // on
        dmx_update();
        wait_us(100000);
    }
}


void dmx_update(){
        enableDMX = 1;
        start = 1;      // /start
        out_tx = 0;     // break
        wait_us(88);    
        out_tx = 1;     // mb
        wait_us(8);     
        out_tx = 0;     // break
        start = 0;
        dmx.putc(0x00);     // Start
        for(int i = 0; i < SAMPLES; i++){
            dmx.putc(dmx_data[i]);     // data
        }
        wait_us(23000); // time between frame  
}