DMXSerial & ShiftPWM - how to combine?

Hi. Attempts to connect the library DMXSerial, sample receiver ShiftPWM library. Here I’m using this code:

const int ShiftPWM_latchPin=8;
const bool ShiftPWM_invertOutputs = false;
const bool ShiftPWM_balanceLoad = true;
 
#include <ShiftPWM.h> // include ShiftPWM.h after setting the pins!
#include <DMXSerial.h>
unsigned char maxBrightness = 255;
unsigned char pwmFrequency = 75;
unsigned int numRegisters = 2;
unsigned int numOutputs = numRegisters*8;
unsigned int numRGBLeds = numRegisters*8/3;
 
void setup(){
DMXSerial.init(DMXReceiver);
 
 
// Sets the number of 8-bit registers that are used.
ShiftPWM.SetAmountOfRegisters(numRegisters);
ShiftPWM.Start(pwmFrequency,maxBrightness);
 
ShiftPWM.SetAll(0);
}
 
void loop(){ 
 
 
} 
 
ShiftPWM.SetOne(0, DMXSerial.read(0));
ShiftPWM.SetOne(1, DMXSerial.read(1));
ShiftPWM.SetOne(2, DMXSerial.read(2));
ShiftPWM.SetOne(3, DMXSerial.read(3));
ShiftPWM.SetOne(4, DMXSerial.read(4));
ShiftPWM.SetOne(5, DMXSerial.read(5));
ShiftPWM.SetOne(6, DMXSerial.read(6));
ShiftPWM.SetOne(7, DMXSerial.read(7));
ShiftPWM.SetOne(8, DMXSerial.read(8));
ShiftPWM.SetOne(9, DMXSerial.read(9));
ShiftPWM.SetOne(10, DMXSerial.read(10)); 
ShiftPWM.SetOne(11, DMXSerial.read(11)); 
ShiftPWM.SetOne(12, DMXSerial.read(12)); 
ShiftPWM.SetOne(13, DMXSerial.read(13));
ShiftPWM.SetOne(14, DMXSerial.read(14)); 
ShiftPWM.SetOne(15, DMXSerial.read(15)); 
}
}

I get this error:

_2:29: error: expected constructor, destructor, or type conversion before ‘.’ token
_2:30: error: expected constructor, destructor, or type conversion before ‘.’ token
_2:31: error: expected constructor, destructor, or type conversion before ‘.’ token
_2:32: error: expected constructor, destructor, or type conversion before ‘.’ token
_2:33: error: expected constructor, destructor, or type conversion before ‘.’ token
_2:34: error: expected constructor, destructor, or type conversion before ‘.’ token
_2:35: error: expected constructor, destructor, or type conversion before ‘.’ token
_2:36: error: expected constructor, destructor, or type conversion before ‘.’ token
_2:37: error: expected constructor, destructor, or type conversion before ‘.’ token
_2:38: error: expected constructor, destructor, or type conversion before ‘.’ token
_2:39: error: expected constructor, destructor, or type conversion before ‘.’ token
_2:40: error: expected constructor, destructor, or type conversion before ‘.’ token
_2:41: error: expected constructor, destructor, or type conversion before ‘.’ token
_2:42: error: expected constructor, destructor, or type conversion before ‘.’ token
_2:43: error: expected constructor, destructor, or type conversion before ‘.’ token
_2:44: error: expected constructor, destructor, or type conversion before ‘.’ token
_2:45: error: expected declaration before ‘}’ token

What needs to be improved. I use Arduino UNO R3 as a receiver thru homemade DMX shield on pin 0(RX)

You have an empty loop() function body. Then, you have a bunch of code that belongs in a function. THAT is not allowed.

I’m using this two code’s and error’s with them:

const int ShiftPWM_latchPin=8;
const bool ShiftPWM_invertOutputs = false;
const bool ShiftPWM_balanceLoad = true;
 
#include <ShiftPWM.h> // include ShiftPWM.h after setting the pins!
#include <DMXSerial.h>
unsigned char maxBrightness = 255;
unsigned char pwmFrequency = 75;
unsigned int numRegisters = 2;
unsigned int numOutputs = numRegisters*8;
unsigned int numRGBLeds = numRegisters*8/3;


#define  DefaultLevel 100


void setup(){
DMXSerial.init(DMXReceiver);
  DMXSerial.write(1, 100);
  DMXSerial.write(2, 100);
  DMXSerial.write(3, 100);
 
// Sets the number of 8-bit registers that are used.
ShiftPWM.SetAmountOfRegisters(numRegisters);
ShiftPWM.Start(pwmFrequency,maxBrightness);
 
ShiftPWM.SetAll(0);
}
 
void loop(){ 
 // Calculate how long no data backet was received
  unsigned long lastPacket = DMXSerial.noDataSince();
  
  if (lastPacket < 5000) {
    // read recent DMX values and set pwm levels 
    ShiftPWM.SetOne(1,  DMXSerial.read(0));
    ShiftPWM.SetOne(2,  DMXSerial.read(1));
    ShiftPWM.SetOne(3,  DMXSerial.read(2));
    ShiftPWM.SetOne(4,  DMXSerial.read(3));
    ShiftPWM.SetOne(5,  DMXSerial.read(4));
    ShiftPWM.SetOne(6,  DMXSerial.read(5));
    ShiftPWM.SetOne(7,  DMXSerial.read(6));
    ShiftPWM.SetOne(8,  DMXSerial.read(7));
    ShiftPWM.SetOne(9,  DMXSerial.read(8));
    ShiftPWM.SetOne(10, DMXSerial.read(9));
    ShiftPWM.SetOne(11, DMXSerial.read(10));
    ShiftPWM.SetOne(12, DMXSerial.read(11));
    ShiftPWM.SetOne(13, DMXSerial.read(12));
    ShiftPWM.SetOne(14, DMXSerial.read(13));
    ShiftPWM.SetOne(15, DMXSerial.read(14));
    ShiftPWM.SetOne(16, DMXSerial.read(15));
    
  } else {
    ShiftPWM.SetOne(1,  DefaultLevel);
    ShiftPWM.SetOne(2,  DefaultLevel);
    ShiftPWM.SetOne(3,  DefaultLevel);
    ShiftPWM.SetOne(4,  DefaultLevel);
    ShiftPWM.SetOne(5,  DefaultLevel);
    ShiftPWM.SetOne(6,  DefaultLevel);
    ShiftPWM.SetOne(7,  DefaultLevel);
    ShiftPWM.SetOne(8,  DefaultLevel);
    ShiftPWM.SetOne(9,  DefaultLevel);
    ShiftPWM.SetOne(10, DefaultLevel);
    ShiftPWM.SetOne(11, DefaultLevel);
    ShiftPWM.SetOne(12, DefaultLevel);
    ShiftPWM.SetOne(13, DefaultLevel);
    ShiftPWM.SetOne(14, DefaultLevel);
    ShiftPWM.SetOne(15, DefaultLevel);
    ShiftPWM.SetOne(16, DefaultLevel);
    
  }
 

}

Error

core.a(HardwareSerial.cpp.o): In function __vector_18': C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/HardwareSerial.cpp:115: multiple definition of __vector_18’
DMXSerial\DMXSerial.cpp.o:C:\Program Files (x86)\Arduino\libraries\DMXSerial/DMXSerial.cpp:353: first defined here
core.a(HardwareSerial.cpp.o): In function __vector_19': C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/HardwareSerial.cpp:218: multiple definition of __vector_19’
DMXSerial\DMXSerial.cpp.o:C:\Program Files (x86)\Arduino\libraries\DMXSerial/DMXSerial.cpp:440: first defined here

And second:

const int ShiftPWM_latchPin=8;
const bool ShiftPWM_invertOutputs = false;
const bool ShiftPWM_balanceLoad = true;
 
#include <ShiftPWM.h> // include ShiftPWM.h after setting the pins!
#include <DMXSerial.h>
unsigned char maxBrightness = 255;
unsigned char pwmFrequency = 75;
unsigned int numRegisters = 2;
unsigned int numOutputs = numRegisters*8;
unsigned int numRGBLeds = numRegisters*8/3;
 
void setup(){
DMXSerial.init(DMXReceiver);
 
 
// Sets the number of 8-bit registers that are used.
ShiftPWM.SetAmountOfRegisters(numRegisters);
ShiftPWM.Start(pwmFrequency,maxBrightness);
 
ShiftPWM.SetAll(0);
}
 
void loop(){ 
 
ShiftPWM.SetOne(0, DMXSerial.read(0));
ShiftPWM.SetOne(1, DMXSerial.read(1));
ShiftPWM.SetOne(2, DMXSerial.read(2));
ShiftPWM.SetOne(3, DMXSerial.read(3));
ShiftPWM.SetOne(4, DMXSerial.read(4));
ShiftPWM.SetOne(5, DMXSerial.read(5));
ShiftPWM.SetOne(6, DMXSerial.read(6));
ShiftPWM.SetOne(7, DMXSerial.read(7));
ShiftPWM.SetOne(8, DMXSerial.read(8));
ShiftPWM.SetOne(9, DMXSerial.read(9));
ShiftPWM.SetOne(10, DMXSerial.read(10)); 
ShiftPWM.SetOne(11, DMXSerial.read(11)); 
ShiftPWM.SetOne(12, DMXSerial.read(12)); 
ShiftPWM.SetOne(13, DMXSerial.read(13));
ShiftPWM.SetOne(14, DMXSerial.read(14)); 
ShiftPWM.SetOne(15, DMXSerial.read(15)); 
}

Error

core.a(HardwareSerial.cpp.o): In function __vector_18': C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/HardwareSerial.cpp:115: multiple definition of __vector_18’
DMXSerial\DMXSerial.cpp.o:C:\Program Files (x86)\Arduino\libraries\DMXSerial/DMXSerial.cpp:353: first defined here
core.a(HardwareSerial.cpp.o): In function __vector_19': C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/HardwareSerial.cpp:218: multiple definition of __vector_19’
DMXSerial\DMXSerial.cpp.o:C:\Program Files (x86)\Arduino\libraries\DMXSerial/DMXSerial.cpp:440: first defined here

Over night I do this little code, change from ShiftPWM Library to Shifter. When compiling there is no errors. But still does not work. Only on shift register, on PIN Q7 led i solid?

// - - - - -
// DmxSerial - A hardware supported interface to DMX.
// DmxSerialRecv.ino: Sample DMX application for retrieving 3 DMX values:
// address 1 (red) -> PWM Port 9
// address 2 (green) -> PWM Port 6
// address 3 (blue) -> PWM Port 5
// 
// Copyright (c) 2011 by Matthias Hertel, http://www.mathertel.de
// This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
// 
// Documentation and samples are available at http://www.mathertel.de/Arduino
// 25.07.2011 creation of the DmxSerial library.
// 10.09.2011 fully control the serial hardware register
//            without using the Arduino Serial (HardwareSerial) class to avoid ISR implementation conflicts.
// 01.12.2011 include file and extension changed to work with the Arduino 1.0 environment
// 28.12.2011 changed to channels 1..3 (RGB) for compatibility with the DmxSerialSend sample.
// 10.05.2012 added some lines to loop to show how to fall back to a default color when no data was received since some time.
// - - - - -
#include <Shifter.h>
#include <DMXSerial.h>

// Constants for demo program

///const int RedPin =    9;  // PWM output pin for Red Light.
///const int GreenPin =  6;  // PWM output pin for Green Light.
///const int BluePin =   5;  // PWM output pin for Blue Light.

#define RedDefaultLevel   100
#define GreenDefaultLevel 200
#define BlueDefaultLevel  255
#define SER_Pin 11 //SER_IN
#define RCLK_Pin 8 //L_CLOCK
#define SRCLK_Pin 13 //CLOCK

#define NUM_REGISTERS 1 //how many registers are in the chain

Shifter shifter(SER_Pin, RCLK_Pin, SRCLK_Pin, NUM_REGISTERS); 
void setup () {
  DMXSerial.init(DMXReceiver);
  
  // set some default values
  DMXSerial.write(1, 80);
  DMXSerial.write(2, 100);
  DMXSerial.write(3, 100);
  
  // enable pwm outputs
  //pinMode(RedPin,   OUTPUT); // sets the digital pin as output
  //pinMode(GreenPin, OUTPUT);
  //pinMode(BluePin,  OUTPUT);
}


void loop() {
  
    shifter.clear(); //set all pins on the shift register chain to LOW
    shifter.write(); //send changes to the chain and display them
  
  // Calculate how long no data backet was received
  unsigned long lastPacket = DMXSerial.noDataSince();
  
  if (lastPacket < 5000) {
    // read recent DMX values and set pwm levels 
    shifter.setPin(1,   DMXSerial.read(1));
    shifter.setPin(2,   DMXSerial.read(2));
    shifter.setPin(3,   DMXSerial.read(3));

  } else {
    // Show pure red color, when no data was received since 5 seconds or more.
    shifter.setPin(1,   RedDefaultLevel);
    shifter.setPin(2, GreenDefaultLevel);
    shifter.setPin(3,  BlueDefaultLevel);
  } // if
}

// End.

Hello after a long break, I managed to resolve all errors. Works on Arduino Uno using Arduino IDE 00021. I switched HardwareSerial.ccp file. And it’s almost okay. When you verify the code does not have any errors. The problem is that on these 3 channels gets the undesired result of accidental flashing.

Below, the code used.

const int ShiftPWM_latchPin=8;
const bool ShiftPWM_invertOutputs = false;
const bool ShiftPWM_balanceLoad = true;

#include <ShiftPWM.h>
#include <DMXSerial.h>

unsigned char maxBrightness = 255;
unsigned char pwmFrequency = 75;
unsigned int numRegisters = 1;
unsigned int numOutputs = numRegisters*8;
unsigned int numRGBLeds = numRegisters*8/3;

#define RedDefaultLevel   100
#define GreenDefaultLevel 200
#define BlueDefaultLevel  255

void setup () {
  ShiftPWM.SetAmountOfRegisters(numRegisters);
  ShiftPWM.Start(pwmFrequency,maxBrightness);
  ShiftPWM.SetAll(0);
  DMXSerial.init(DMXReceiver);
  
  // set some default values
  DMXSerial.write(1, 80);
  DMXSerial.write(2, 0);
  DMXSerial.write(3, 0);
  
}


void loop() {
  unsigned long lastPacket = DMXSerial.noDataSince();
  
  if (lastPacket < 5000) {
    ShiftPWM.SetOne(1,  DMXSerial.read(1));
    ShiftPWM.SetOne(2,  DMXSerial.read(2));
    ShiftPWM.SetOne(3,  DMXSerial.read(3));

  } else {
    ShiftPWM.SetOne(1,   RedDefaultLevel);
    ShiftPWM.SetOne(2, GreenDefaultLevel);
    ShiftPWM.SetOne(3,  BlueDefaultLevel);
  } 
}