Hello,
I'm not very well versed in programming so hopefully the problem will be obvious to you.
I've constructed a device which essentially has 16 laser diodes (although i say led as it a shorter word), each connected to a pin on an Uno (pins 2-17). These are arranged in a row and it is my wish to have them flash in pleasing ways.
Firstly, training wheels on, I'd like to program a simple sweep from left to right.
However, I would like to throw in some complications and have a bit of random variety with the flashing. There are three variables that I would like to influence this:
ONE: the number of lasers turned on, the width, moving up the row. I call this ledQty.
TWO: the speed that it runs through each sweep, i.e. the delay before moving on to the next laser. I call this ledSpeed.
THREE: the duration of the sequence, i.e. the amount of times it loops through. I call this ledDuration.
Now I try to set these as random numbers between the limits shown but only the first two lasers illuminate. I know the lasers work because of the test loop in setup.
Now what I've written does look a bit silly so I think it must be something in my nested loops but I could be wrong.
Please be nice, and try to focus on this problem as I know there is more refining to do, but I need this core principle working first.
Here's my code:
/*
for laser strip standalone operation.
*/
const int pinMin = 2; // first laser
const int pinMax = 17; // last laser
const int pintotal = 16; // pinMax - pinMin + 1 = number of lasers
// I was thinking of using arrays, but if that isn't the solution please ignore this bit
//const int lasers[16] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17};
//const int lasersSym[2][8] = { { 2, 3, 4, 5, 6, 7, 8, 9},
// {17,16,15,14,13,12,11,10} };
// Variables
long ledQty = 1;
long ledSpeed = 100;
long ledDuration = 10;
void setup() {
// Pin setup
for(int i=pinMin; i<=pinMax; i++){
pinMode(i, OUTPUT); // set pins to output
digitalWrite(i, LOW); // set pins to LOW
}
// Test Loop
for(int i=pinMin; i<=pinMax; i++){
digitalWrite(i, HIGH);
delay(600);
digitalWrite(i, LOW);
}
}
void loop() {
// set random variables
ledQty = random(0, 5);
ledSpeed = random(5, 2000);
ledDuration = random(1, 20);
// Sweep Left to Right
for(int h=1; h<=ledDuration; h++){
for(int i=pinMin; i<=pinMax; i++){
for(int j=i; j<=i+ledQty; j++){
digitalWrite(j, HIGH);
}
delay(ledSpeed);
for(int j=i; j=i+ledQty; j++){
digitalWrite(j, LOW);
}
}
}
// Sweep Right to Left
// Sweep Ping Pong
// Sweep Out to In
// Sweep In to Out
// Random Pulse
// Random Pulse Symmetrical
}
Thanks,
Pat