0% found this document useful (0 votes)
18 views1 page

Wyndell Rio P. Claveria EE-4204 Activity Practice 2

The document describes a program that uses a potentiometer to control the brightness of LEDs in a bar graph. It explains how the program reads the potentiometer, maps the value to a range to control the number of LEDs lit, and uses a for loop to light the correct number.

Uploaded by

WyndellRio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views1 page

Wyndell Rio P. Claveria EE-4204 Activity Practice 2

The document describes a program that uses a potentiometer to control the brightness of LEDs in a bar graph. It explains how the program reads the potentiometer, maps the value to a range to control the number of LEDs lit, and uses a for loop to light the correct number.

Uploaded by

WyndellRio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Wyndell Rio P.

Claveria // read the potentiometer:

EE-4204 int sensorReading =


analogRead(analogPin);
Activity Practice 2
// map the result to a range from 0 to
the number of LEDs:

int ledLevel = map(sensorReading, 0,


1023, 0, ledCount);

// loop over the LED array:

for (int thisLed = 0; thisLed < ledCount;


thisLed++)

// if the array element's index is less


than ledLevel,

const int analogPin = A0; // the pin that the


potentiometer is attached to // turn the pin for this element on:
const int ledCount = 10; // the number of LEDs if (thisLed < ledLevel)
in the bar graph
{
int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
digitalWrite(ledPins[thisLed],
HIGH);
void setup() }
{ // turn off all pins higher than the
ledLevel:
// loop over the pin array and set them
all to output: else
for (int thisLed = 0; thisLed < ledCount; {
thisLed++)
digitalWrite(ledPins[thisLed],
{ LOW);
pinMode(ledPins[thisLed], OUTPUT); }
} }
} }

void loop()

You might also like