Adding a button! I carried many of the skills I learned last week over to this week.
Now, the button controls the fade!
Thank you to my classmates Hannah and Antya, for assisting me with this exercise! Here’s the code we came up with…
/*
Fade with Button
*/
int led = 9; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 1; // how many points to fade the LED by
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 9; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
//if the button is pressed,increased fade amount by 1
fadeAmount = fadeAmount + 5;
}
// set the brightness of pin 9:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 





…and I am part of the 2019 Product of Design program at the School of Visual Arts. I was born and raised in Canandaigua, NY, in the heart of the Finger Lakes, where I also completed a four year degree in Architectural Studies from Hobart and William Smith Colleges in Geneva, NY. Following graduation in 2016, I was able to feed my appetiteĀ for travel by visiting some new places in central and eastern Europe, and spent my summerĀ in a furniture maker’s wood shop honing my woodworking skill set. Prior to coming to NYC, I spent the last year in Boston, MA working in the field of graphic design. This fall I am excited to learn how to channel my design ideas through the world of Arduino! Follow me along the way on Instagram