ok yeah now i am really confused i don’t really understand any of that
what i am trying to do here for example
is have one led fade off and another fade on at the same time
i thought i might be able to make 2 void loops one that does the inverse of the other
like fade in pin1 and fade out pin4 in one loop then another loop that says fade in pin4 and fade out pin1
i am getting really confused trying to get the timing to how i want it
i need 6 pins to be fading in and out
i want to have 2 pins fading on and then fading off as another 2 pins fade on
and the other 2 pins the fade on and off opposite of one another but on a different delay
i want to have 2 or 3 pins faded on at one time with them all fading in and out at different times
i wonder if there is a way to cod this to make it do it randomly
there is another sketch i am using for another project i copied from someones project that moves servos randomly but i am not sure how i would adapt it to the led fade sketch or if can be done the same way
here is that code
// Random multiple
// by 68percentwater
// This code generates a random position for each of 12 servos, pauses and then repeats.
#include <Servo.h> //this is a servo library
Servo servo1; // create servo objects to control multiple servos
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;
Servo servo7;
Servo servo8;
Servo servo9;
Servo servo10;
Servo servo11;
Servo servo12;
int pos = 90; // variable to store the servo position with a starting position of 90 degrees
// so the eyes go to the middle at startup
void setup()
{
servo1.attach(2); // attaches the servos on pins 2 - 13 to the servo objects
servo2.attach(3);
servo3.attach(4);
servo4.attach(5);
servo5.attach(6);
servo6.attach(7);
servo7.attach(8);
servo8.attach(9);
servo9.attach(10);
servo10.attach(11);
servo11.attach(12);
servo12.attach(13);
servo1.write(pos); //tell all servos to go to middle position (90 degrees)
servo2.write(pos);
servo3.write(pos);
servo4.write(pos);
servo5.write(pos);
servo6.write(pos);
servo7.write(pos);
servo8.write(pos);
servo9.write(pos);
servo10.write(pos);
servo11.write(pos);
servo12.write(pos);
delay(700);
}
void loop() // for each servo, generate a random number between 10 and 170 and
{ // assign to pos then write the pos to the servo. This is done in three groups
pos =random(10,170); // with a delay to make it appear the eyes are not all starting at the same time.
servo1.write(pos); // I use 10 and 170 because the last 10 deg on either side jammed my
pos = random(10,170); // mechanism. Depending on you mech, these might need to be other limits
servo2.write(pos); // They don’t need to be all the same, each eye can have its own range
pos = random(10,170);
servo3.write(pos);
delay(200);
pos = random(10,170);
servo4.write(pos);
pos = random(10,170);
servo5.write(pos);
pos = random(10,170);
servo6.write(pos);
pos = random(10,170);
servo7.write(pos);
pos = random(10,170);
servo8.write(pos);
delay(300);
pos = random(10,170);
servo9.write(pos);
pos = random(10,170);
servo10.write(pos);
pos = random(10,170);
servo11.write(pos);
pos = random(10,170);
servo12.write(pos);
delay(200);
}
here is what i am working with so far on my fade sketch it works ok but i think i would like something a little more random and so far i only have 2 pins lit at one time mostly
i do plan on connecting two sets of eyes to one pin though so i will get 3 on at once part of the time
*/
int ledPin1 = 9; // LED connected to digital pin 9
int ledPin2 = 10;
int ledPin3 = 11;
int ledPin4 = 6;
int ledPin5 = 5;
int ledPin6 = 3;
void setup() {
// nothing happens in setup
}
void loop() {
// fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin1, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(25);
}
// fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin6, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(25);
}
delay(5000);
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin1, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(12);
}
delay (5000);
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin2, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(25);
}
delay(5000);
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin2, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(12);
}
delay(5000);
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin6, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(12);
}
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin3, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(25);
}
delay(5000);
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin3, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(12);
}
delay(5000);
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin4, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(25);
}
delay(10000);
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin2, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(25);
}
delay(5000);
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin4, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(12);
}
delay(5000);
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin5, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(25);
}
delay(5000);
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin2, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(12);
}
delay (3000);
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin5, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(12);
}
delay(100);
}
i really don;t have all that much time to do this i am going to be putting these out this week and i have lots to do , this sketch works ok for now i guess but i think maybe a randomizer might look better