Lab 1 – Dim and Blink

Description:

I added a Dim effect from some code examples online. I had the LED blink once it reached its max brightness, before dimming back down to zero.

Components:

Arduino
Breadboard
Resistor (220 Ohms)
Red, Black, Green Jumper
Green LED

Code:

int ledPin = 9;
int delay_time = 50;
int brightness = 0;
int fadeAmount = 5;

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

void loop()
{

if (brightness==255) {
analogWrite(ledPin, 0);
delay(1000);
analogWrite(ledPin, brightness);
}
else {
analogWrite(ledPin, brightness);
}

brightness = brightness + fadeAmount;

if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}

delay(delay_time);

}

IMG_20160831_154050

One thought on “Lab 1 – Dim and Blink

Leave a Reply