wait for digital input (arduino uno and dmx 512 board)

hello,

i have some problems with programming the arduino,

i have a program from the internet that almost does what we need, now is the challenge to change the program that it will wait for an input but i don’t know how. can somebody help me?

The program:

#include <DMXSerial.h>

int plc = 13;
int val = 0;

// 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.

// The color fading pattern

int RedList = { 0, 255, 10, 0, 0, 0};
int GreenList = { 0, 0, 0, 0, 0, 0};
int BlueList = { 0, 0, 0, 255, 255, 0};

int RedLevel, GreenLevel, BlueLevel;

int RedNow = 0;
int GreenNow = 0;
int BlueNow = 0;

int state = 0;

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

pinMode(plc, INPUT);
pinMode(RedPin, OUTPUT); // sets the digital pin as output
pinMode(GreenPin, OUTPUT);
pinMode(BluePin, OUTPUT);
} // setup

// loop through the rainbow colors
void loop() {
val = digitalRead(plc); // read the input pin

RedLevel = RedList[state];
GreenLevel = GreenList[state];
BlueLevel = BlueList[state];

if ((RedLevel == RedNow) && (GreenLevel == GreenNow) && (BlueLevel == BlueNow)) {
state += 1;
if (state == 6)
state = 0;

} else {
if (RedNow < RedLevel) RedNow++;
if (RedNow > RedLevel) RedNow–;
DMXSerial.write(1, RedNow);
analogWrite(RedPin, RedNow);

if (GreenNow < GreenLevel) GreenNow++;
if (GreenNow > GreenLevel) GreenNow–;
DMXSerial.write(2, GreenNow);
analogWrite(GreenPin, GreenNow);

if (BlueNow < BlueLevel) BlueNow++;
if (BlueNow > BlueLevel) BlueNow–;
DMXSerial.write(3, BlueNow);
analogWrite(BluePin, BlueNow);

} // if

delay(30); // wait a little bit
} // loop

this is the program and now i have to change it that is wil stop at some point and wait for an digital input
( int plc = 13;)

when this input is HIGh (1)

then the program must start from where is was stopped

the original pattern for the led lights is:

int RedList = { 0, 255, 10, 0, 0, 0};
int GreenList = { 0, 0, 0, 0, 0, 0};
int BlueList = { 0, 0, 0, 255, 255, 0};

and this the pattern we want.

int RedList = { 0, 255,} wait for digital input (pin 13) {10, 0, 0, 0};
int GreenList= { 0, 0,} wait for digital input (pin 13) { 0, 0, 0, 0};
int BlueList = { 0, 0, } wait for digital input (pin 13) { 0, 255, 255, 0};

can someone help me please?

and this the pattern we want.

int RedList = { 0, 255,} wait for digital input (pin 13) {10, 0, 0, 0};
int GreenList= { 0, 0,} wait for digital input (pin 13) { 0, 0, 0, 0};
int BlueList = { 0, 0, } wait for digital input (pin 13) { 0, 255, 255, 0};
No, that is wrong. The pattern does not change. WHEN the next element in the list is applied is what changes.

When the program reaches the end of the list, it starts over again at the beginning. What should happen when you add the "wait for pin 13 to represent pressed" code?

it is for dutch carnival. it is for a show.

first the collor must be red and then when i give a signal from the plc to pin 13 (or another pin) of the arduino the collor must change to blue.

after a few seconds the collor gets back to red en when we start the show again we give again the signal from the plc to turn the led lights blue.

now is my problem that i don't know how to program it in arduino.

I don't know how to help you. There are 6 colors listed. You talk about two of them.

See the StateChangeDetection example in Examples > 02.Digital > StateChangeDetection

what we want is that the led spots first are red and after a pin (for example pin 10) gets high the led light turn in to blue.

this program we use now does what we want but we can't stop it.

so is is what te program does:

// The color fading pattern

int RedList[]   = {255,   10,  0,    0,  };
int GreenList[] = {0,     0,   0,    0,  };
int BlueList[]  = {0,     0,   255,  255,};

this program starts with red at 255, after that he lowers the red (to 10) en turn on the blue lights (255).

now i must change the program that he wil stop after he set red to 255 and when a pin gets high he continuous the program. (red 10 -------blue 255)

You are STILL not answering the questions. There are 6 values in the arrays. If you set the LEDs to the first set in setup() and then wait for a switch to be pressed before setup ends, EXACTLY what do you expect to happen in loop()?

Should loop() move to 1, 2, 3, 4, 5, and 0, and then wait for the switch to be pressed again?

Should pressing the switch interrupt the cycling?

You can't begin to write code until you have a set of implementable requirements. All you have conveyed to us is that the program needs to do something (anything?) different from what it does now.