#define Switch A0
#define pot A1
#define LED 3
int State, potVal, brightness;
void setup() {
Serial.begin(9600);
pinMode(Switch, INPUT_PULLUP);
pinMode(pot, INPUT);
pinMode(LED, OUTPUT);
}
void loop() {
State = digitalRead(Switch);
potVal = analogRead(pot);
//Serial.print("State: "); Serial.println(State);
//Serial.print("potVal: "); Serial.println(potVal);
//delay(100);
//brightness = map(potVal, 0, 1023, 255, 0);
//analogWrite(LED, brightness);
if (State == 0){
fade();
}
else {
blink();
}
}
void fade(){
for(int x = 0; x <=255; x++){
analogWrite(LED, x); delay(5);
}
for(int x = 255; x >=0; x--){
analogWrite(LED, x); delay(5);
}
}
void blink(){
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
}