pinMode(11, OUTPUT);
digitalWrite(11, HIGH);
digitalWrite(11, LOW);
The two lines:
delay(1000);
It is imperative to add a resistor to the circuit to prevent the LED from blowing up.
const int buttonPin = 2; // the number on the pushbutton pin
const int ledPin = 13; to const int ledPin =9; // the number on the LED pin
Change if(buttonState==HIGH) to if (buttonState == LOW)
const int buttonPin = 2;
const int ledPin = 9;
int buttonState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}
Which lines of code do you need to modify to correspond with your button and LED pins?
int ledPin = 9; // LED connected to digital pin 9
fadeValue +=5 //change the fade increase rate
delay(30); //change the delay time
The fadeValue should change logarithmically: fadeValue+=sqrt(fadeValue) when fading in and : fadeValue-=sqrt(fadeValue) when fading out.
The voltage drop across the LED is 3.2 V. Since the total voltage supplied is 5 V, the voltage across the resistor is 5-3.2 = 1.8 V.
Since R = V/I ,
R= 1.8/0.03 = 60 ohms.
Using this photo to draw a schematic: