Controlling 8 BIT SMD LED Array by Potentiometer 100k
In this intractable, we want to control
8 bit smd led array by Potentiometer.
Code:
Picture of the completed hardware in operation
Step
1:
Materials
Required
1. Arduino (We use UNO)
2.
8 Bit Smd Led
Array
3.
Potentiometer
100k
4. Jumper wires Male - Female
Software
Required
1. Arduino IDE (We use NSight Eclipse)
Circuit Diagram
Step
2:
Uploading Arduino Program
Code:
#include
#include
int main (void)
{
unsigned char result;
// OUTPUT
DDRD = DDRD | 0b11111111; // Make all port d pins as output
// ADC SETUP CODE
/* 1. */ DDRC = DDRC | 0b00111111; // Make all of PORT C as INPUT
/* 2. */ ADMUX = ADMUX | 0b01100000; // SELECT 5V and LEFT ADJUST
/* 3. */ ADCSRA |= (1 << ADEN); // Turn on the ADC module
/* 4. */ _delay_ms(10);
/* 5. */ ADCSRA = ADCSRA | 0b00000100; // Select divide by 16
while (1)
{
// ADC USAGE
/* 1. */ ADMUX = ADMUX & 0b11110000; // select default ADC0
/* 2. */ ADMUX = ADMUX | 0b00000010; // select ADC2
/* 3. */ ADCSRA |= (1 << ADSC); // Start conversion
/* 4. */ while (!(ADCSRA & 0b00010000)); // POLLING UNTIL
// CONVERSION COMPLETE
/* 5. */ ADCSRA |= (1 << ADIF); // Clear the ADIF flag
/* 6. */ result = ADCH; // read the ADC result
PORTD = result;
}
return 0;
}
Picture of the completed hardware in operation
Finally, now we can control Led by
Potentiometer.On the Led we can see output shows value from 0 to 254.
Comments
Post a Comment