hi So I have 12 leds in a line, and I am using binary notation to turn them on and off. I have patterns stored in an enumerator, and I pass the fnction Display that goes through the binary string to look for a 1 in the pattern and if it exists, it blinks the corresponding led on for a given length of time. and then moves to the next one in the sequence.
It works nicely, however i want it to go up and down the pattern, and it does that but it repeats the top and bottom led. I can see why it does that in the code, but I cant work out how to stop it. I tried moving the mask along, but then it shifts the entire pattern in the line of leds. I tried stopping the for loop early, but that doesnt seem to have an affect - and I know why... I cant just cut the top or bottom off the for loop, because it may not be that led that is meant to be lit i.e if you have 5 leds in a line, and the pattern is to light leds 2 and 4, then cutting one or 5 out of the loop wouldn't stop it lighting, so you still get 2 twice, and then 4 twice. It seems somehow the loop needs to know whether this is the last led in the pattern to be lit?????
Any ideas? Function below:
enum Pattern{
P1 = 0b100010010000,
P2 = 0b001000100100,
P3 = 0b000010001001,
};
void Display(unsigned int Pattern, int time){
int mask = 0b100000000000;
for(int i=0; i<12; i++){
if((mask & Pattern) == 0){
}
else {
Ledpattern(i, time);
}
mask = mask >> 1;
}
mask = 0b000000000001;
for(int i=11; i>=0; i--){
if((mask & Pattern) == 0){
}
else {
Ledpattern(i, time);
}
mask = mask << 1;
}
}