Welcome, %1$s. Please login or register. - Did you miss your activation email?

Login with username, password and session length
 

Author Topic: Silly beginner question  (Read 229 times)

Offline scottminium

  • Admiral
  • *****
  • Posts: 1106
  • There are submarines, and targets.
Silly beginner question
« on: May 05, 2018, 04:22:18 pm »
Hello!  I've just started with Arduino and have a few nanos.

I am trying to dim an LED (yellow), with the standard 'fading' code:

const int EngPin=8;
void setup() {
//nothing
}
// the loop function runs over and over again forever
void loop() {
  // 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(EngPin, fadeValue);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
  }
}

The problem is that the light only turns on and off, and is off when the fadeValue is <128.  Got any hints as to what I am doing wrong?
The electrical lineup is strictly per the plans, 220ohm, 5v from the pin.

Thanks!
"I rather believe that time is a companion who goes with us on the journey, and reminds us to cherish every moment... because they'll never come again."

Offline LynnInDenver

  • Commander
  • ***
  • Posts: 236
    • My husband and I on YouTube - TG256
Re: Silly beginner question
« Reply #1 on: May 05, 2018, 05:41:54 pm »
I think the pin you're using isn't one set up for "pulse width modulation", or PWM. On the Arduino board, PWM pins are marked with a ~ character before the number.

Offline scottminium

  • Admiral
  • *****
  • Posts: 1106
  • There are submarines, and targets.
Re: Silly beginner question
« Reply #2 on: May 06, 2018, 08:05:01 am »
Holy wrong pin, I really am a n00b!  :o    OK, I'll give that a shot, and thanks for the clue Lynn!
"I rather believe that time is a companion who goes with us on the journey, and reminds us to cherish every moment... because they'll never come again."

Offline scottminium

  • Admiral
  • *****
  • Posts: 1106
  • There are submarines, and targets.
Re: Silly beginner question
« Reply #3 on: May 06, 2018, 03:11:16 pm »
It works!  video to follow!
"I rather believe that time is a companion who goes with us on the journey, and reminds us to cherish every moment... because they'll never come again."

 




Enterprise © Bloc