Functions

/*
* Functions:
* If button1 is pressed, the led will fade up/down.
* If button2 is pressed, the led will flash.
* Number of flashes is determined by potentiometer.
*/

//integer for button1
const int button1 = 15;
//integer for button2
const int button2 = 16;
//integer for LED
const int led = 9;

//integer for pot
const int pot = A0;
//int for pot reading
int potValue = 0;

void setup() {

//set LED to output
pinMode(led, OUTPUT);

//set buttons to input
pinMode(button1, INPUT);
pinMode(button2, INPUT);
}

void loop() {

//check pot reading
potValue = analogRead(pot);

//check for button1
if (digitalRead(button1)) {
function1();
}

if (digitalRead(button2)) {
function2(potValue);
}

}

//function for button1
void function1() {
//fade up
for (int x = 0; x < 256; x++) {

//set LED to x value
analogWrite(led, x);
//delay to slow fading
delay(5);
}
//fade down
for (int x = 255; x &gt;= 0; x—) {
//set LED to x value
analogWrite(led, x);
//delay to slow fading
delay(5);
}
}

//function for button2
void function2(int potInput) {

//scale pot input down by factor of 100
potInput = potInput / 100;

//flash LED based on pot
for (int count = 0; count <= potInput; count++) {

//flash LED on/off
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
delay(100);
}
}