Go Down

Topic: led matrix - problem with the corner leds (Read 1 time)previous topic - next topic

etayl

Dec 06, 2012, 12:42 pm
Hey everybody,
i'm using the LedControl librery and i want to do a simple task of turning on the leds of a certain row.
i want to lit the first and then the first two, the first three and repeat 8 times until all of the leds in this raw are on.
first i did it as follows:
Code: [Select]
`lc.setRow(0,0,1);delay(300);lc.setRow(0,0,3);delay(300);lc.setRow(0,0,7);delay(300);lc.setRow(0,0,15);delay(300);lc.setRow(0,0,31);delay(300);lc.setRow(0,0,63);delay(300);lc.setRow(0,0,127);delay(300);lc.setRow(0,0,255);delay(300);`

than i wanted to use the for loop so the code is:
Code: [Select]
`for (int i=1;i<9;i++){     lc.setRow(0,1,pow(2,i)-1);     delay(300);   }`

where pow(2,i)-1 gives me the values (1,3,7,15,31,63,127,255)
i checked with the serial  monitor and indeed i get these values in the loop BUT
the outcome of the display is a bit different.
if i use the for loop what i see as as followes:
the first is on then the first is off.
the second is on, the third is on etc... until all row beside the first are on.
this dirves me crazy cause the command for the 'lc.setRow' gets the same values when runnig in the for loop or if i enter in row by row but the outcome of the display is different.
thanks for yout patience,
Etay

johnwasser

#1
Dec 06, 2012, 04:14 pm
I think the pow() function produces a floating-point result which may give you 1.9999 instead of 2.  When you subtract the integer 1 it converts 1.99999 to the integer 1 and ten subtracts 1 to get 0.

Try using the shift operator instead of the pow() function:

Code: [Select]
`for (int i=1;i<9;i++){     lc.setRow(0,1,(1<<i)-1);     delay(300);   }`
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

#2
:-)
it's working...
thanks alot
etay

Go Up