Code for Lex Matrix

Hello everyone.

for (int i=4; i>=0; i--)  {
            if ( x & (1<<i) )
            pinState= 1;
          else
            pinState= 0;

  }

Can you explain this code .
Thanks.

taipscode:

 for (int i=4; i>=0; i--)  {

if ( x & (1<<i) )
            pinState= 1;
          else
            pinState= 0;

}

The only side-effect of that loop is to set pinState. The last time through the look the value of 'i' is zero. The result is that pinState is left set to 'x & (1<<0))'. Since 1 shifted left by 0 bits is 1, the entire loop is equivalent to:

pinState = x & 1;

Looks like a waste of time.

I suspect that the pinState should have been used to set the values of four different pins (digitalWrite(pin*, pinState):wink: The effect then would be to set those pins to match the bottom four bits of X.*

Thanks for reply of Mr Johnwasser.

void loop(){
 
 for(int x=0;x<16;x++){ // start a line scan
    digitalWrite(E_pin, HIGH);    
    byte_checker = (unsigned long)1 << 0;
 
    for(int y = 0; y < 64; y++) { // setup a scan of 64 iterations to find out the column led
       //000 R2 R1 G2 G1 CLK
       byte row = B00011110; // Default to R[1|2] G[1|2] off and CLOCK to low.
        // G1 
          g1 = x*2;
          g2 = (x*2) + 32;
          r1 = (x*2) + 64;
          r2 = (x*2) + 96;
        if (y==32)
          byte_checker = (unsigned long)1 << 0;
        if (y > 31) {
          g1++;
          g2++;
          r1++;
          r2++;
        }
    
         if (displayBitmap[g1] & byte_checker)
         row ^= (1 << 1); 
    
        if (displayBitmap[g2] & byte_checker)
         row ^= (1 << 2); 
    
        if (displayBitmap[r1] & byte_checker)
         row ^= (1 << 4); 
    
        if (displayBitmap[r2] & byte_checker)
         row ^= (1 << 3); 

        byte_checker <<= 1;        
        PORTB = row;
        delayMicroseconds(1); //needed to not toggle the clock too fast
        PORTB |= B00000001; // Clock back to HIGH
     }// End a scan of 64
    
       digitalWrite(E_pin, LOW);   
       digitalWrite(L_pin,HIGH); // latch the data
       digitalWrite(L_pin,LOW);  

       int pinState = 0;
       int abcd_pins[] = {A_pin,B_pin,C_pin,D_pin};

       for (int i=4; i>=0; i--)  {
            if ( x & (1<<i) )
            pinState= 1;
          else
            pinState= 0;

          digitalWrite(abcd_pins[i], pinState);
        }
       digitalWrite(E_pin, HIGH);   
       delayMicroseconds(xdelay);
  
  }
}

This is code for scan 64 columns and 32 rows.
Can you help me to modify for 128 columns and 32 rows .
Thanks.

This is a full code.pde
http://www.mediafire.com/?hxax22mac7syk1x

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.

I think the code is actually something like this:

for (int i=4; i>=0; i--)  {
   if ( x & (1<<i) )
      pinState= 1;
   else
     pinState= 0;

   // AND HERE WE DO SOMETHING USEFUL WITH PINSTATE
}

This is bitmap code. The first time through the loop, i is 4. So it is checking to see if bit 4 of x is set and if it is, pinState is set to 1, otherwise pinState is set to 0. The second time through the loop, i is 3. So it is checking to see if bit 3 of x is set and if it is, pinState is set to 1, otherwise pinState is set to 0. ... The last time through the loop, i is 0. So it is checking to see if bit 0 of x is set and if it is, pinState is set to 1, otherwise pinState is set to 0.

Hello everyone.

Can you help me to modify for 128 columns and 32 rows ?

Thanks

Spending three days ,noboby help me ,hic hic....

What is the "hic hic"? A joke?

I asked you above to put your posted code in code tags. You ignored me. And you are asking why people are ignoring you?

Sorry Mr Nick Gammon.

I just added my code in (code][/code) . I don't try to ignore ,because this is especially in your forum.

Spending four days, nobody help me =(

taipscode:
This is code for scan 64 columns and 32 rows.
Can you help me to modify for 128 columns and 32 rows.

I tried but I can't. That code is very specific to the hardware it was designed for (8x8 red-green modules). The hardware includes a 1-of-16 decoder and four parallel sets of shift registers connected to specific pins. To expand it in both directions you will need the shift register chains to be twice as long and you will need twice as many of them. Unfortunately you can't fit eight chains of shift registers AND a clock signal all on PORTB which is an 8-bit port.

Perhaps you should try one of the many other matrix examples or libraries. ShiftPWM is a nice library for controlling a large number of LEDs using shift registers.

If you REALLY REALLY want code based on this (crappy) example you will probably have to pay someone to develop it. Figure about six hours of coding at about $20/hour. You will also have to specify how your LEDs, shift registers, and decoders are wired because the software will only work on specific hardware.

Thanks Mr Johnwasser.