Tutorial.DMXMaster History

Hide minor edits - Show changes to markup

June 05, 2010, at 11:27 AM by Equipo Traduccion -
Changed line 3 from:

Por favor visita estetutorial actualizado en el playground.

to:

Por favor visita este tutorial actualizado en el playground.

June 05, 2010, at 11:26 AM by Equipo Traduccion -
Changed line 3 from:

Please see this updated tutorial on the playground.

to:

Por favor visita estetutorial actualizado en el playground.

January 30, 2007, at 10:35 PM by David A. Mellis -
Changed lines 2-176 from:

full tutorial coming soon

  
/* DMX Shift Out
 * -------------
 *
 * Shifts data in DMX format out to DMX enabled devices
 * it is extremely restrictive in terms of timing. Therefore
 * the program will stop the interrupts when sending data
 *
 * (cleft) 2006 by Tomek Ness and D. Cuartielles
 * K3 - School of Arts and Communication
 * <http://www.arduino.cc>
 * <http://www.mah.se/k3>
 * 
 * @date: 2006-01-19
 * @idea: Tomek Ness
 * @code: D. Cuartielles and Tomek Ness
 * @acknowledgements: Johny Lowgren for his DMX devices
 *
 */

int sig = 3;           // signal (plus / dmx pin 3)
int sigI = 2;          // signal inversion (minus / dmx pin 2)
int count = 0;


/* Sends a DMX byte out on a pin.  Assumes a 16 MHz clock. 
 * Disables interrupts, which will disrupt the millis() function if used
 * too frequently. */
void shiftDmxOut(int pin, int ipin, int theByte)
{
        int theDelay = 1;
	int count = 0;
	int portNumber = port_to_output[digitalPinToPort(pin)];
	int pinNumber = digitalPinToBit(pin);
	int iPortNumber = port_to_output[digitalPinToPort(ipin)];
	int iPinNumber = digitalPinToBit(ipin);

	// the first thing we do is to write te pin to high
	// it will be the mark between bytes. It may be also
	// high from before
        _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
        _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
	delayMicroseconds(20);

	if (digitalPinToPort(pin) != NOT_A_PIN) {
		// If the pin that support PWM output, we need to turn it off
		// before doing a digital write.

		if (analogOutPinToBit(pin) == 1)
			timer1PWMAOff();

		if (analogOutPinToBit(pin) == 2)
			timer1PWMBOff();
	}

	// disable interrupts, otherwise the timer 0 overflow interrupt that
	// tracks milliseconds will make us delay longer than we want.
	cli();

        // DMX starts with a start-bit that must always be zero
        _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
        _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        delayMicroseconds(theDelay);
        delayMicroseconds(theDelay);

        if (theByte & 01) {
          _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
        }
	else {
          _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        }
        delayMicroseconds(theDelay);
    	theByte>>=1;
        if (theByte & 01) {
          _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
        }
	else {
          _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        }
        delayMicroseconds(theDelay);
    	theByte>>=1;
        if (theByte & 01) {
          _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
        }
	else {
          _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        }
        delayMicroseconds(theDelay);
        theByte>>=1;
        if (theByte & 01) {
          _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
        }
        else {
          _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        }
        delayMicroseconds(theDelay);
        theByte>>=1;
        if (theByte & 01) {
          _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
        }
        else {
          _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        }
        delayMicroseconds(theDelay);
        theByte>>=1;
        if (theByte & 01) {
          _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
        }
        else {
          _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        }
        delayMicroseconds(theDelay);
        theByte>>=1;
        if (theByte & 01) {
          _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
        }
        else {
          _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        }
        delayMicroseconds(theDelay);
        theByte>>=1;
        if (theByte & 01) {
          _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
        }
        else {
          _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        }
        delayMicroseconds(theDelay);
        theByte>>=1;

	// the last thing we do is to write te pin to high
	// it will be the mark between bytes. 
        _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);

	// reenable interrupts.
	sei();
}

void setup() {
  pinMode(sig, OUTPUT); 
  pinMode(sigI, OUTPUT); 
}

void loop()  {
   digitalWrite(sig, LOW); 
   digitalWrite(sigI, HIGH);     
   delay(10);

   //sending the start byte
   shiftDmxOut(3,2,0);

   //set all adresses/channels to 60%
   for (count = 1; count<=512; count++){
     shiftDmxOut(3,2,155);
   }
 }

to:

Please see this updated tutorial on the playground.

January 20, 2006, at 12:03 AM by 195.178.229.101 -
Added lines 1-176:

DMX Master Device

full tutorial coming soon

  
/* DMX Shift Out
 * -------------
 *
 * Shifts data in DMX format out to DMX enabled devices
 * it is extremely restrictive in terms of timing. Therefore
 * the program will stop the interrupts when sending data
 *
 * (cleft) 2006 by Tomek Ness and D. Cuartielles
 * K3 - School of Arts and Communication
 * <http://www.arduino.cc>
 * <http://www.mah.se/k3>
 * 
 * @date: 2006-01-19
 * @idea: Tomek Ness
 * @code: D. Cuartielles and Tomek Ness
 * @acknowledgements: Johny Lowgren for his DMX devices
 *
 */

int sig = 3;           // signal (plus / dmx pin 3)
int sigI = 2;          // signal inversion (minus / dmx pin 2)
int count = 0;


/* Sends a DMX byte out on a pin.  Assumes a 16 MHz clock. 
 * Disables interrupts, which will disrupt the millis() function if used
 * too frequently. */
void shiftDmxOut(int pin, int ipin, int theByte)
{
        int theDelay = 1;
	int count = 0;
	int portNumber = port_to_output[digitalPinToPort(pin)];
	int pinNumber = digitalPinToBit(pin);
	int iPortNumber = port_to_output[digitalPinToPort(ipin)];
	int iPinNumber = digitalPinToBit(ipin);

	// the first thing we do is to write te pin to high
	// it will be the mark between bytes. It may be also
	// high from before
        _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
        _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
	delayMicroseconds(20);

	if (digitalPinToPort(pin) != NOT_A_PIN) {
		// If the pin that support PWM output, we need to turn it off
		// before doing a digital write.

		if (analogOutPinToBit(pin) == 1)
			timer1PWMAOff();

		if (analogOutPinToBit(pin) == 2)
			timer1PWMBOff();
	}

	// disable interrupts, otherwise the timer 0 overflow interrupt that
	// tracks milliseconds will make us delay longer than we want.
	cli();

        // DMX starts with a start-bit that must always be zero
        _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
        _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        delayMicroseconds(theDelay);
        delayMicroseconds(theDelay);

        if (theByte & 01) {
          _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
        }
	else {
          _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        }
        delayMicroseconds(theDelay);
    	theByte>>=1;
        if (theByte & 01) {
          _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
        }
	else {
          _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        }
        delayMicroseconds(theDelay);
    	theByte>>=1;
        if (theByte & 01) {
          _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
        }
	else {
          _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        }
        delayMicroseconds(theDelay);
        theByte>>=1;
        if (theByte & 01) {
          _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
        }
        else {
          _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        }
        delayMicroseconds(theDelay);
        theByte>>=1;
        if (theByte & 01) {
          _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
        }
        else {
          _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        }
        delayMicroseconds(theDelay);
        theByte>>=1;
        if (theByte & 01) {
          _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
        }
        else {
          _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        }
        delayMicroseconds(theDelay);
        theByte>>=1;
        if (theByte & 01) {
          _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
        }
        else {
          _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        }
        delayMicroseconds(theDelay);
        theByte>>=1;
        if (theByte & 01) {
          _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber);
        }
        else {
          _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber);
          _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber);
        }
        delayMicroseconds(theDelay);
        theByte>>=1;

	// the last thing we do is to write te pin to high
	// it will be the mark between bytes. 
        _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber);

	// reenable interrupts.
	sei();
}

void setup() {
  pinMode(sig, OUTPUT); 
  pinMode(sigI, OUTPUT); 
}

void loop()  {
   digitalWrite(sig, LOW); 
   digitalWrite(sigI, HIGH);     
   delay(10);

   //sending the start byte
   shiftDmxOut(3,2,0);

   //set all adresses/channels to 60%
   for (count = 1; count<=512; count++){
     shiftDmxOut(3,2,155);
   }
 }

Share