homework for week 2: Blink and lighten

The blink frequency and brightness of LED can be both controlled at the same time by the knob.

IMG_9051_2

 

 

/*
LED -> GND, 9
KNOB -> (middle) ANALOG IN 0
-> (other) 5V, GND
*/

int buttonPin = 2;
int ledPin = 9;
int potpin = 0;
int val, f;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}

void loop() {
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 179);
f = (180 – val) * 2;

analogWrite(ledPin, val);
delay(f);
analogWrite(ledPin, val/3);
delay(f);
}

Leave a Reply

Your email address will not be published.