Video below shows LED light controlled by forward and reverse switch. When forward button is press, LED will shift to the right and reverse button will make the LED shift to the left. When LED is shifted until the last one, it will back to the first one again.
Programming part
//This is the desired array looks like
unsigned char _options[8]={0b00000001, 0b00000010, 0b00000100, 0b00001000,
0b00010000, 0b00100000, 0b01000000, 0b10000000};
sel=0;
PORTD =_options[sel]; //assign PORTD output to follow the array
//this is where button assigned to move forward or reverse
while(1)
{
if(forward==1)
{
if(sel==7) sel=0;
else sel++;
PORTD =_options[sel];
while(forward==1); //waiting for button to be press
}
else if(reverse==1)
{
if(sel==0) sel=7;
else sel--;
PORTD =_options[sel];
while(reverse==1);
}
No comments:
Post a Comment