help a noob with a fun halloween project, LED fade

ok so i am really new and i hate programing anything ,i much prefer to build things instead
i am not good at coding at all
last year i used a pro mini to make a really basic project from to blink these led eye lights
i made

using this code

void setup() {
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(9,OUTPUT);

}

void loop() {
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
delay(5000);
digitalWrite(2,LOW);
digitalWrite(3,HIGH);
delay(5000);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
delay(6000);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
delay(6000);
digitalWrite(9,HIGH);
digitalWrite(6,LOW);
delay(6000);
digitalWrite(9,LOW);
digitalWrite(6,HIGH);
delay(6000);

}

what i would like to do this year is make them fade on , stay lit for a 5 or 6 seconds then fade off

i looked at the fade example sketch and some explanations of how it works and it is WAY over my head i was not able to extrapolate from the example sketch how to change the code to make the LED's fade on , stay lit for a set amount of seconds before fading off again

i am just not good at this coding stuff at all , so if someone could help me out here
and write me a simple code to fade in the LED's or point me to another project that uses similar code that would help a lot
also if there is a way to make it fade in and out the LED's on the different GPIO pins randomly that would be even better
i tried to make it look like the blinking is sorta random by changing the dealy and connecting two sets of eyes up to one GPIO pin
i plan on having 7 or 8 sets and want about 2, 3 ,or 4 sets to be on at one time and have them fading on staying on a few seconds and then fading off , even better if one set is fading off at the same time another set is fading on

Use the PWM out pins, 3,5,6,9,10,11, and change the analogWrite value over time to create a fade:

/*
 Fading
 
 This example shows how to fade an LED using the analogWrite() function.
 
 The circuit:
 * LED attached from digital pin 9 to ground.
 
 Created 1 Nov 2008
 By David A. Mellis
 modified 30 Aug 2011
 By Tom Igoe
 
 http://arduino.cc/en/Tutorial/Fading
 
 This example code is in the public domain.
 
 */

int ledPin = 9;    // LED connected to digital pin 9


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(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect    
    delay(30);                            
  } 


  // 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(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect    
    delay(30);                            
  } 
}

Or you fake PWM with software if you need more than 6.

ok NM i figured it out
not really sure what the difference is between the example fade sketch and the example fading sketch i mean besides one giving the opportunity to add a delay function
they both say analog but are they?
is there a an example sketch for fading on non analog /PWN pins ?

Sure. You would have to turn the led on and off for varying amounts of time in each state with the total being too short for eyes to detect. It's very simple to do for 1 led if you can write code past beginner level which is something nobody is born knowing. To make it work for > 1 led takes a bit more that we teach here as a turning point in being able to write automation code.

The analog pins make it easier. The real name is pulse width modulated (PWM) which is not real analog but can be smoothed into analog. An Uno has PWM that pulses every almost-2 millis and PWM that pulses every almost-1 milli.

Haven't you got any nerdy friends you can get to code for you? I get that you don't want to learn so team effort is your best way.

still having trouble here
i figured out how to add the delay but now i can not get it to work with more than one LED/GPIO pin

what am i doing wrong here ?

*/

int ledPin = 9; // LED connected to digital pin 9
int ledpintwo = 10; //LED connected to digital pin 10
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(ledPin, 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(ledPin, 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(ledPintwo, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(25);
}
delay(5000);

}

i get this error “ledpintwo was not declared in this scope”

NM rookie mistake forgot to capitalize

i figured out how to add the delay but now i can not get it to work with more than one LED/GPIO pin

If you want them to blionk at the same time then answer/solution is in this tutorial:
http://gammon.com.au/blink

This question comes up practically every day on the Arduino forum - "how do I blink two LEDs at different rates?" or "how do I turn on and off two motors at different times?".

But if you don't want at-the-same-time,

int ledpintwo = 10; //LED connected to digital pin 10

analogWrite(ledPintwo, fadeValue);

those are not the same variable and compiling that sketch should tell you that ledPintwo was not declared.

ok i already figured that out i know i forgot to capitalize Pin
what i am asking now is
is there a way to write the code so that i can have 2 sets of instructions
one that runs concurrently and one that runs consecutively ?
or several sets of consecutive instructions that will run concurrently

Arduino does not run concurent code. However it runs fast, so you can code that runs within microseconds, and an observer thinks it's concurent.

Aross1976:
ok i already figured that out i know i forgot to capitalize Pin
what i am asking now is
is there a way to write the code so that i can have 2 sets of instructions
one that runs concurrently and one that runs consecutively ?
or several sets of consecutive instructions that will run concurrently

It is as Chris says, the speed of the code can be incredible like monitor an input pin while blinking a led and printing out data on every change in a loop that runs > 60x every millisecond. Sure an input change might get caught 20 to 50 micros "late" because a print took that bit later but when the smoothness goal is response in 1 milli or less then you're more concurrent than a PC running a multi-tasking OS like Windoze or Linux.

Trick is that every routine in the code must not hog the CPU as long or longer than your acceptable response time. So no calls to delay(), every milli delayed is 16000 CPU cycles LOST to the rest of the sketch. If you need to process an array that's not very small, don't add a for-next or while loop and do them all before anything else gets a chance to run -- make the array index a global variable that says which array element to process each time that void loop() runs and change the index after processing one element so that next time through void loop() the next element runs. Yes, lots of passes through void loop() to finish the array but the concurrent-running sections all get a chance and lots of passes at > 50 or 60 KHz get done almost as quick as in a blocking big for-next while the rest of the sketch stays on time.

This is event-driven code. If it's non-blocking it will run like lightning.

void loop()
{
if ( timed event condition )
{
// process the event
}

if ( pin change event condition )
{
// process the event
}

if ( certain variable changed event condition )
{
// process the event
}

if ( Serial.available() event condition )
{
// process the event
}

}

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

read how toHow To Use This Forum to understand how to post your code.

stuff like this does not work well

servo7.attach(8);

OP needs to learn about arrays. Whole new dimensions will open up.