Morse code to DMX512 transmitter

Hi All,
I am building a light sculpture that has two parts
the two parts will have (simulated) conversation in morse code by way of flashing lights.
I am using wireless DMX to get the signal to the lights and a DMX shield to get the signal out of Arduino land.
I am using a variant of the excellent morse code code found here on git hub here.
and the conceptikinetics DMX library.

THE PROBLEM:
I have managed to get one channel of DMX to flash the morse code. but i need to alternate the channels to simulate the "conversation" ie:
channel1 (hello)
channel2 (hi)
channel1 (soooo)
and so on ( i promise to think of something more interesting for the sculpture to say!)

a penny for your thoughts!

Please see code attached, the action is near the end where I have made the morse code operate channel 1 in DMX land. ( maybe it is possible to select this channel in the Void loop instead. i have tried a bunch of things but TBH i am not a programmer and its all guesswork and google for me... and hours... and hours....

//THIS IS A SECOND GO AT DOING A ARDUINO CODE THAT
//READS A LINE OF A STORED "CONVERSATION"
//CONVERTS TO MORSE CODE
//SENDS THE MORSE PHRASE TO DMX ADRESS 1
//THEN
//PROGRAM READS THE NEXT LINE 
//CONVERTS TO MORSE CODE
//SENDS THE MORSE PHRASE TO DMX ADRESS 2
// SO LETS GO!!!

//DMX LIBRARY 
#include <Conceptinetics.h>


//DMX PIN AND NUMBER OF CHANNELS
#define RXEN_PIN                2
#define DMX_MASTER_CHANNELS   10

// Configure a DMX master controller, the master controller
// will use the RXEN_PIN to control its write operation 
// on the bus
DMX_Master        dmx_master ( DMX_MASTER_CHANNELS, RXEN_PIN );

//NOW THE MORSE CODE STUFF

//Define the LED Pin
#define PIN_OUT        13 ///remnant from when it was flashing led
//Define unit length in ms
#define UNIT_LENGTH    200

//Build a struct with the morse code mapping
static const struct {const char letter, *code;} MorseMap[] =
{
  { 'A', ".-" },
  { 'B', "-..." },
  { 'C', "-.-." },
  { 'D', "-.." },
  { 'E', "." },
  { 'F', "..-." },
  { 'G', "--." },
  { 'H', "...." },
  { 'I', ".." },
  { 'J', ".---" },
  { 'K', "-.-" },
  { 'L', ".-.." },
  { 'M', "--" },
  { 'N', "-." },
  { 'O', "---" },
  { 'P', ".--." },
  { 'Q', "--.-" },
  { 'R', ".-." },
  { 'S', "..." },
  { 'T', "-" },
  { 'U', "..-" },
  { 'V', "...-" },
  { 'W', ".--" },
  { 'X', "-..-" },
  { 'Y', "-.--" },
  { 'Z', "--.." },
  { ' ', "     " }, //Gap between word, seven units 
    
  { '1', ".----" },
  { '2', "..---" },
  { '3', "...--" },
  { '4', "....-" },
  { '5', "....." },
  { '6', "-...." },
  { '7', "--..." },
  { '8', "---.." },
  { '9', "----." },
  { '0', "-----" },
    
  { '.', ".-.-.-" },
  { ',', "--..--" },
  { '?', "..--.." },
  { '!', "-.-.--" },
  { ':', "---..." },
  { ';', "-.-.-." },
  { '(', "-.--." },
  { ')', "-.--.-" },
  { '"', ".-..-." },
  { '@', ".--.-." },
  { '&', ".-..." },
};
//MORE MORSE CODE STUFF

void doMorse(int pin, const char *string) {
  size_t i, j;
  
  for( i = 0; string[i]; ++i )
  {
    for( j = 0; j < sizeof MorseMap / sizeof *MorseMap; ++j )
    {
      if( toupper(string[i]) == MorseMap[j].letter )
      {
        emitMorse(pin, MorseMap[j].code);
        break;
      }
    }
    emitMorse(pin, "  "); //Add tailing space to separate the chars
  }
}
// NOW I THINK ITS DOING A SWITCHCASE FOR THE DITS AND DAHS....

void emitMorse(int pin, const char *morseString) {
  for(int i=0; morseString[i]; i++)
  {
    switch( morseString[i] )
    {static int dimmer_val;

//THIS BIT READS THE MORSE AND SENDS TO DMX CHANNEL 1
// THE 100 DOLLAR QUESTION IS HOW CAN SEND EACH LINE OF TEXT TO ALTERNATING  DMX CHANNELS??


    
// I THINK THIS BIT IS THE PROBLEM_ BY MAKING THE SWITCH CASE DRIVE THE DMX DIRECTLY 
//ITS HARD TO CHANGE THE CHANNEL VALUES 
case '.': //dit
     dmx_master.setChannelValue ( 1, 255 );
        delay( UNIT_LENGTH );
     dmx_master.setChannelValue ( 1, 0 );
        delay( UNIT_LENGTH );
          
        break;

      case '-': //dah
    dmx_master.setChannelValue ( 1, 255); 
        delay( UNIT_LENGTH*3 );
    dmx_master.setChannelValue ( 1, 0 ); 
        delay( UNIT_LENGTH );
          
        break;

      case ' ': //gap
        delay( UNIT_LENGTH );
    }
  }
}


void setup() 
 

{ 
  // Enable DMX master interface and start transmitting
  dmx_master.enable ();  
  
  // Set channel 1 - 10 @ 0%
  dmx_master.setChannelRange ( 1, 10, 000 );
  
  // NOT SURE IF THIS BIT IS STILL BEING USED
  pinMode( PIN_OUT, OUTPUT );
  digitalWrite( PIN_OUT, LOW );
}


void loop()
{
 

  delay(1000);                       // wait for a second
  doMorse(PIN_OUT, "HELLO");           //PERSON 1 CHANNEL 1
  delay(1000);                       // wait for a second
  doMorse(PIN_OUT, "HOW ARE YOU");   // PERSON 2 CHANNEL 2
  delay(1000);
  doMorse(PIN_OUT, "GOOD THANK YOU");  //PERSON 1 CHANNEL 1
 }

When you send the strings, change the PIN_OUT to the DMX channel you want

  delay(1000);                       // wait for a second
  doMorse(PIN_OUT, "HELLO");           //PERSON 1 CHANNEL 1
  delay(1000);                       // wait for a second
  doMorse(PIN_OUT, "HOW ARE YOU");   // PERSON 2 CHANNEL 2
  delay(1000);
  doMorse(PIN_OUT, "GOOD THANK YOU");  //PERSON 1 CHANNEL 1

and then replace the fixed DMX channel of 1 with pin

void emitMorse(int pin, const char *morseString) {
  for(int i=0; morseString[i]; i++)
  {
    switch( morseString[i] )
    {static int dimmer_val;
      
      //THIS BIT READS THE MORSE AND SENDS TO DMX CHANNEL 1
      // THE 100 DOLLAR QUESTION IS HOW CAN SEND EACH LINE OF TEXT TO ALTERNATING  DMX CHANNELS??
      
      
      
      // I THINK THIS BIT IS THE PROBLEM_ BY MAKING THE SWITCH CASE DRIVE THE DMX DIRECTLY
      //ITS HARD TO CHANGE THE CHANNEL VALUES
      case '.': //dit
      dmx_master.setChannelValue ( 1, 255 );
      delay( UNIT_LENGTH );
      dmx_master.setChannelValue ( 1, 0 );
      delay( UNIT_LENGTH );
      
      break;
      
      case '-': //dah
      dmx_master.setChannelValue ( 1, 255);
      delay( UNIT_LENGTH*3 );
      dmx_master.setChannelValue ( 1, 0 );
      delay( UNIT_LENGTH );
      
      break;
      
      case ' ': //gap
      delay( UNIT_LENGTH );
    }
  }
}

Legend Riva!
i will give it a go right now!

Problem Solved. Much respect to Riva and my friend Lemming who helped as well
both light are working great now on the tow channels see code below:

declared the DMX_CHAN variable

//set DMX channel
int DMX_CHAN;

swapped out the static DMX channel for the variable

dmx_master.setChannelValue ( DMX_CHAN, 255 );
        delay( UNIT_LENGTH );
     dmx_master.setChannelValue ( DMX_CHAN, 0 );
        delay( UNIT_LENGTH );
          
        break;

      case '-': //dah
    dmx_master.setChannelValue ( DMX_CHAN, 255); 
        delay( UNIT_LENGTH*3 );
    dmx_master.setChannelValue ( DMX_CHAN, 0 ); 
        delay( UNIT_LENGTH );

and then set the DMX_CHAN as required in the void loop

void loop()
{
 
  delay(1000);                       // wait for a second
  
  DMX_CHAN = 1;
  doMorse(PIN_OUT, "HELLO");           //PERSON 1 CHANNEL 1
  
    delay(2000);                       // wait for a second
    
  DMX_CHAN = 4;
  doMorse(PIN_OUT, "HOW ARE YOU");   // PERSON 2 CHANNEL 2

    delay(2000);

  DMX_CHAN = 1;
  doMorse(PIN_OUT, "GOOD THANK YOU");  //PERSON 1 CHANNEL 1

:slight_smile: :slight_smile: :slight_smile: it seems so simple now but if you knew how many hours i tried to work it out myself.........
thanks again.

Glad it works but you have created another variable called DMX_CHAN when you could have just replaced the PIN_OUT parameter with your DMX channel number and adjusted the emitMorse() procedure to use that parameter.
Pretty much the same code as you originally had but have applied the changes I was talking about.

//THIS IS A SECOND GO AT DOING A ARDUINO CODE THAT
//READS A LINE OF A STORED "CONVERSATION"
//CONVERTS TO MORSE CODE
//SENDS THE MORSE PHRASE TO DMX ADRESS 1
//THEN
//PROGRAM READS THE NEXT LINE
//CONVERTS TO MORSE CODE
//SENDS THE MORSE PHRASE TO DMX ADRESS 2
// SO LETS GO!!!

//DMX LIBRARY
#include <Conceptinetics.h>


//DMX PIN AND NUMBER OF CHANNELS
#define RXEN_PIN               2
#define DMX_MASTER_CHANNELS   10

// Configure a DMX master controller, the master controller
// will use the RXEN_PIN to control its write operation
// on the bus
DMX_Master dmx_master ( DMX_MASTER_CHANNELS, RXEN_PIN );

//NOW THE MORSE CODE STUFF

//Define unit length in ms
#define UNIT_LENGTH    200

//Build a struct with the morse code mapping
static const struct {const char letter, *code;} MorseMap[] =
{
  { 'A', ".-" },
  { 'B', "-..." },
  { 'C', "-.-." },
  { 'D', "-.." },
  { 'E', "." },
  { 'F', "..-." },
  { 'G', "--." },
  { 'H', "...." },
  { 'I', ".." },
  { 'J', ".---" },
  { 'K', "-.-" },
  { 'L', ".-.." },
  { 'M', "--" },
  { 'N', "-." },
  { 'O', "---" },
  { 'P', ".--." },
  { 'Q', "--.-" },
  { 'R', ".-." },
  { 'S', "..." },
  { 'T', "-" },
  { 'U', "..-" },
  { 'V', "...-" },
  { 'W', ".--" },
  { 'X', "-..-" },
  { 'Y', "-.--" },
  { 'Z', "--.." },
  { ' ', "     " }, //Gap between word, seven units
  
  { '1', ".----" },
  { '2', "..---" },
  { '3', "...--" },
  { '4', "....-" },
  { '5', "....." },
  { '6', "-...." },
  { '7', "--..." },
  { '8', "---.." },
  { '9', "----." },
  { '0', "-----" },
  
  { '.', ".-.-.-" },
  { ',', "--..--" },
  { '?', "..--.." },
  { '!', "-.-.--" },
  { ':', "---..." },
  { ';', "-.-.-." },
  { '(', "-.--." },
  { ')', "-.--.-" },
  { '"', ".-..-." },
  { '@', ".--.-." },
  { '&', ".-..." },
};
//MORE MORSE CODE STUFF

void doMorse(int dmx_channel, const char *string) 
{
  size_t i, j;
  
  for( i = 0; string[i]; ++i )
  {
    for( j = 0; j < sizeof MorseMap / sizeof *MorseMap; ++j )
    {
      if( toupper(string[i]) == MorseMap[j].letter )
      {
        emitMorse(dmx_channel, MorseMap[j].code);
        break;
      }
    }
    emitMorse(dmx_channel, "  "); //Add tailing space to separate the chars
  }
}
// NOW I THINK ITS DOING A SWITCHCASE FOR THE DITS AND DAHS....

void emitMorse(int dmx_channel, const char *morseString) 
{
  for(int i=0; morseString[i]; i++)
  {
    switch( morseString[i] )
    {
      static int dimmer_val;
      
      //THIS BIT READS THE MORSE AND SENDS TO DMX CHANNEL 1
      // THE 100 DOLLAR QUESTION IS HOW CAN SEND EACH LINE OF TEXT TO ALTERNATING  DMX CHANNELS??
      
      
      
      // I THINK THIS BIT IS THE PROBLEM_ BY MAKING THE SWITCH CASE DRIVE THE DMX DIRECTLY
      //ITS HARD TO CHANGE THE CHANNEL VALUES
      case '.': //dit
      dmx_master.setChannelValue ( dmx_channel, 255 );
      delay( UNIT_LENGTH );
      dmx_master.setChannelValue ( dmx_channel, 0 );
      delay( UNIT_LENGTH );
      
      break;
      
      case '-': //dah
      dmx_master.setChannelValue ( dmx_channel, 255);
      delay( UNIT_LENGTH*3 );
      dmx_master.setChannelValue ( dmx_channel, 0 );
      delay( UNIT_LENGTH );
      
      break;
      
      case ' ': //gap
      delay( UNIT_LENGTH );
    }
  }
}


void setup()
{
  // Enable DMX master interface and start transmitting
  dmx_master.enable (); 
  // Set channel 1 - 10 @ 0%
  dmx_master.setChannelRange ( 1, 10, 0 );
}

void loop()
{
  delay(1000);                       // wait for a second
  doMorse(1, "HELLO");           //PERSON 1 CHANNEL 1
  delay(1000);                       // wait for a second
  doMorse(2, "HOW ARE YOU");   // PERSON 2 CHANNEL 2
  delay(1000);
  doMorse(1, "GOOD THANK YOU");  //PERSON 1 CHANNEL 1
}
}

Thats even better Riva!
Thank you, i couldn't quite understand the first time.
That does make sense now.
B.