hey hey,
so I am a current year 12 student and am creating a product that involves an led light fading in and out to manage breathing, a technique used to calm anxiety.
what I plan on doing is connecting an power button to my already fading led light to turn on and off the light so that the light is not consistently being used, wasting unnecessary power.
this is the code I have already implemented to fade my led light:
int brightness = 0;
void setup()
{
pinMode(9,OUTPUT);
}
void loop()
{
for (brightness = 0; brightness <= 255; brightness += 5) {
analogWrite(9, brightness);
delay(40); // Wait for 3000 millisecond(s)
}
for (brightness = 255; brightness >= 0; brightness -= 5) {
analogWrite(9, brightness);
delay(50); // Wait for 3000 millisecond(s)
}
}
I am also using a Arduino Nano to power my circuit.
is someone able to help me code a button power to my circuit to turn on and off the fading LED light?
Thank you!
is someone able to help me code a button power to my circuit to turn on and off the fading LED light?
Set the mode of some pin to INPUT_PULLUP. Connect one leg of a switch to that pin. Connect the other leg to ground.
Use digitalRead() to read the state of the pin. When it is HIGH, the switch is not being pressed/is not on. When the pin is LOW, the switch is being pressed/is on.
It is trivial to compare the state of the pin to some value, in an if statement. The fading then happens in the body of the if statement.
Hi,
Welcome to the forum.
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html . Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Thanks... Tom.. 
This is what my current circuit looks like!