Pages: 1 [2]   Go Down
Author Topic: I need assistance with a project.  (Read 1103 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 2
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you so much man! God, this is really one of the most helpful communities I've been a part of already! Now to make it slowly turn on. I'll post again if I run into anymore trouble.


Well I'd actually like you to see also post when you have good things to report not just your problems.  smiley-grin

Lefty
Alright, now that it's working and I've tried on my own to make it slowly turn on and have failed, I'm turning to you again. I am assuming my code is far off. I don't know exactly how to make this argument. Here's what I got! I'l post a picture or video once I've got it installed!
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17303
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok not tested, but it compiles OK. Note that we are going to gradually turn on the led from full off to full on via PWM control of the led using analogWrite() commands. But pin 13 isn't one of the available PWM output pins, so we have to move the led to pin 10, and be sure to use a series resistor with the led. You can increase or decrease the speed of the ramping up of the LED by changing the value inside the delay(10) command.

Good luck;

Lefty

Code:
const int buttonPin = 2;    
      
int PWMpin = 10; // LED in series with 470 ohm resistor on pin 10


int buttonState = 0;        

void setup() {
  pinMode(PWMpin, OUTPUT);      
  pinMode(buttonPin, INPUT);    
}

void loop(){
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {        
    
      for (int i=0; i <= 255; i++){
           analogWrite(PWMpin, i);
           delay(10);
       }  
  }
  else {
    digitalWrite(PWMpin, LOW);
  }
}
« Last Edit: December 04, 2012, 11:34:41 pm by retrolefty » Logged

Pages: 1 [2]   Go Up
Jump to: