Pages: [1]   Go Down
Author Topic: led matrix - problem with the corner leds  (Read 447 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8821
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
for (int i=1;i<9;i++){
     lc.setRow(0,1,(1<<i)-1);
     delay(300);
   }
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

:-)
it's working...
thanks alot
etay
Logged

Pages: [1]   Go Up
Jump to: