Hi, I am a beginner in arduino, in really ned help to make a program with to fade a led, e
and switch it on of, with two buttons. can anyone help me with the code ? button1 turn ON, and fade op. Buttun two fade down and turn off.
Have you worked through any of the examples provided in the IDE?
Yes some of theme, but i i need learn more, think its so difficult.
int Led = 5;
int switch1 = 7;
int switch2 =8;
void setup() {
pinMode(5,OUTPUT);
pinMode(7,INPUT_PULLUP);
pinMode(8,INPUT_PULLUP);
}
void loop() {
if(digitalRead(7) == LOW) Led--;
if(Led < 0) Led = 5;
if(digitalRead(8) == LOW) Led++;
if(Led > 255) Led = 255;
analogWrite(5, Led);
delay(30)
i did this one for fade, but now how to turn it on and off, with the switches
fabregas:
Yes some of theme, but i i need learn more, think its so difficult.int Led = 5;
int switch1 = 7;
int switch2 =8;
void setup() {
pinMode(5,OUTPUT);
pinMode(7,INPUT_PULLUP);
pinMode(8,INPUT_PULLUP);
}
void loop() {
if(digitalRead(7) == LOW) Led--;
if(Led < 0) Led = 5;
if(digitalRead(8) == LOW) Led++;
if(Led > 255) Led = 255;
analogWrite(5, Led);
delay(30)
}
i did this one for fade, but now how to turn it on and off, with the switches
Please use code tags.
Using appropriate variable and constant names will help you figure out what's wrong.
Use 'const int ledPin = 5' and 'int brightness = 0' for example.
You probably mean: 'if(Led < 0) Led = 0;'
You declared variables for input pins, but you didn't use them. Also, they should be constants.
Pieter