Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flips out after 3 channels #79

Open
tonyxforce opened this issue Jul 31, 2023 · 0 comments
Open

flips out after 3 channels #79

tonyxforce opened this issue Jul 31, 2023 · 0 comments

Comments

@tonyxforce
Copy link

tonyxforce commented Jul 31, 2023

I have 2 servos and 4 LEDs attached to pins 3, 5, 6, 9, 10, 11 and the 2 servos work fine with the first 2 channels, and the first led works perfectly, but when i try to bring up the brightness of the second led (channel 4) the servos start moving randomly in random directions and the led doesn't light up, the third led just doesn't light up at all, the fourth led(channel 6) lights up perfectly.

code:

#include <Servo.h>
#include <DMXSerial.h>

Servo pan;
Servo tilt;

const int panPin = 3;
const int tiltPin = 5;
const int RedPin =    6;  // PWM output pin for Red Light.
const int GreenPin =  9;  // PWM output pin for Green Light.
const int BluePin =   10;  // PWM output pin for Blue Light.
const int WhitePin = 11;


int panPos = 0;
int tiltPos = 0;

int lastPanPos = 0;
int lastTiltPos = 0;

const int startChannel = 0 * 6 + 1;

#define RedDefaultLevel   128
#define GreenDefaultLevel 128
#define BlueDefaultLevel  128
#define WhiteDefaultLevel 128

void setup() {
  DMXSerial.init(DMXReceiver);

  // set some default values
  DMXSerial.write(1, 0);
  DMXSerial.write(2, 0);
  DMXSerial.write(3, 80);
  DMXSerial.write(4, 0);
  DMXSerial.write(5, 0);
  DMXSerial.write(6, 0);


  pan.attach(panPin);
  tilt.attach(tiltPin);
  pinMode(RedPin,   OUTPUT); 
  pinMode(GreenPin, OUTPUT);
  pinMode(BluePin,  OUTPUT);
  pinMode(WhitePin, OUTPUT);

}


void loop() {

  if (lastPanPos != panPos) {
    lastPanPos = panPos;
    pan.write(panPos);
  };


  if (lastTiltPos != tiltPos) {
    lastTiltPos = tiltPos;
    tilt.write(tiltPos);
  };


  unsigned long lastPacket = DMXSerial.noDataSince();

  if (lastPacket < 5000) {
    // read recent DMX values and set pwm levels
    pan.write(            DMXSerial.read(startChannel + 0));
    tilt.write(           DMXSerial.read(startChannel + 1));
    analogWrite(RedPin,   DMXSerial.read(startChannel + 2));
    analogWrite(GreenPin, DMXSerial.read(startChannel + 3));
    analogWrite(BluePin,  DMXSerial.read(startChannel + 4));
    analogWrite(WhitePin, DMXSerial.read(startChannel + 5));



  } else {
    // Show pure red color, when no data was received since 5 seconds or more.
    panPos = 0;
    tiltPos = 0;
    analogWrite(RedPin,   RedDefaultLevel);
    analogWrite(GreenPin, GreenDefaultLevel);
    analogWrite(BluePin,  BlueDefaultLevel);
    analogWrite(WhitePin, WhiteDefaultLevel);

  }
}

edit: formatting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant