Noob here, help needed, small program

Hi

Can you please help me find my mistake /missing program ??

I wish that the program light up 4 led. (1 steady on, and the other 3 will be dimable ) then if i press a switch they will hold lighting up all of them until i press the switch again. I also attached the program. by the way im trying to do some adjustments on an example that i found in the examples folder.

nb

the switch is spst (not momentary)

the board arduino uno

thanks in advance

Josef

jonfade_jan23a.ino (3.41 KB)

What is the problem with the program you attached ?

NOTE : that it would have been easier if you had Auto formatted it in the IDE and posted it here in code tags like this

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

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Fading
*/
int ledPinRed = 3;      // LED connected to digital pin 3
int ledPinGreen = 5;    // LED connected to digital pin 5
int ledPinBlue = 6;     // LED connected to digital pin 6
int ledPinWhite = 8;    // LED connected to digital pin 8

// if statment component items

int i;
int button = 7;         // switch connected to digital pin 7
int ledRed = 3;         // LED connected to digital pin 3
int ledGreen = 5;       // LED connected to digital pin 5
int ledBlue = 6;        // LED connected to digital pin 6
int ledWhite = 8;       // LED connected to digital pin 8


void setup()
{
  // put your setup code here, to run once:
  pinMode(ledPinRed, OUTPUT);
  pinMode(ledPinGreen, OUTPUT);
  pinMode(ledPinBlue, OUTPUT);
  pinMode(ledPinWhite, OUTPUT);
  // if statment component items
  pinMode(button, INPUT);
  pinMode(ledRed, OUTPUT);
  pinMode(ledGreen, OUTPUT);
  pinMode(ledBlue, OUTPUT);
  pinMode(ledWhite, OUTPUT);
}

void loop()
{
  // put your main code here, to run repeatedly:
  if (digitalRead(button) == HIGH)
  {
    digitalWrite(ledRed, HIGH);
    digitalWrite(ledGreen, HIGH);
    digitalWrite(ledBlue, HIGH);
    digitalWrite(ledWhite, HIGH);
  }
  else
  {
    digitalWrite(ledRed, LOW);
    digitalWrite(ledGreen, LOW);
    digitalWrite(ledBlue, LOW);
    digitalWrite(ledWhite, LOW);
  }
  digitalWrite(ledPinWhite, HIGH);
  // fade in from min to max in increments of 5 points:
  //dimming of red colour//
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5)
  {
    // sets the value (range from 0 to 255):
    analogWrite(ledPinRed, 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(ledPinRed, fadeValue);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
  }
  //dimming of green colour//
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5)
  {
    // sets the value (range from 0 to 255):
    analogWrite(ledPinGreen, 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(ledPinGreen, fadeValue);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
  }
  //dimming of blue colour//
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5)
  {
    // sets the value (range from 0 to 255):
    analogWrite(ledPinBlue, 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(ledPinBlue, fadeValue);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
  }
}

Please do this in future when posting code

Don’t give the same pins different names - you’ll confuse yourself and everyone else.

the problem is that when i push the switch the led dont stay on they switch on at a time then they began dimming again without pressing the switch

hi
thanks for your reply @UKHeliBob

How can i post the code like you did, as i dont have a clue how it should be done . I was trying to find on the internet but up till now i found nothing.

thanks for your time
josef

How can i post the code like you did, as i dont have a clue how it should be done .

Auto format the code in the IDE then copy it into a post here, select it all then click the </> icon top/left of the editor window and code tags will be added to the highlighted text

Preview the post to make sure that you did it correctly

hi it was solved by putting the dimming code in the if statment