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
}