Exemple #1
0
void LEDBar::sendLED(uint16_t data)
{
    unsigned char i;
    for (i = 0; i<12; i++) {
        if (data & 0x0001)
            send16bitData(0x00ff);
        else
            send16bitData(0x0000);
        data = data >> 1;
    }
}
void sendLED(unsigned int LEDstate)
{
  unsigned char i;
  for(i=0;i<12;i++)
  {
    if(LEDstate&0x0001)
      send16bitData(ON);
    else
      send16bitData(SHUT);
    LEDstate=LEDstate>>1;
  }
}
// set led single bit, red to green, one bit for each led
// such as, index_bits = 0x05, then led 1 and led 3 will be on and the others will be off
// 0x0   = 0b000000000000000 = all leds off
// 0x05  = 0b000000000000101 = leds 1 and 3 on, the others off
// 0x155 = 0b000000101010101 = leds 1,3,5,7,9 on, 2,4,6,8,10 off
// 0x3ff = 0b000001111111111 = all leds on
void led_bar_index_bit(unsigned int index_bits)
{
    send16bitData(CMDMODE);

    for (int i=0;i<12;i++)
    {
        unsigned int state = (index_bits&0x0001) ? ON : SHUT;
        send16bitData(state);

        index_bits = index_bits>>1;
    }

    latchData();
}
// set level 0-10, red to green, where 1 is red
// level 0 means all leds off while level 5 means leds 1-5 on and 6-10 will be off
void led_bar_set_level(int level)
{
    if(level>10)return;

    send16bitData(CMDMODE);

    for(int i=0;i<12;i++)
    {
        unsigned int state1 = (i<level) ? ON : SHUT;
        
        send16bitData(state1);
    }

    latchData();
}
int setLedNum(int n)
{
	if(n<0 || n >10){
		printf("n = [0, 10]\n");
		return -1;
	}

    send16bitData(CmdMode);
    sendLED(pow(2,n)-1); // 2^n-1
    latchData();
}
Exemple #6
0
void MatrixDriver::updateLine()
{
    unsigned char i, k, lineBits;


    // disable decoder while configuring the next line
    DEC_PORT &=~ _BV(DEC_E3);

    // clear the MY9221 before we send the data for the next line
    for (k=0;k<2;k++) {
		send16bitData(CmdMode);
		MY9221_PORT &=~ _BV(MY9221_DI);
		for(i=0;i<192;i++) {
			// toggle clock pin
			MY9221_PORT ^= _BV(MY9221_DCKI);
		}
    }

    latchData();

    // now send the real data
    // first data segment for the 2nd MY9221 chip
    send16bitData(CmdMode);
    // BLUE segment
    send16bitData(0);    // A3 --> BLUE8
    send16bitData(255);  // B3 --> BLUE7
    send16bitData(0);    // C3 --> BLUE6
    send16bitData(255);  // A2 --> BLUE5
    send16bitData(0);    // B2 --> BLUE4
    send16bitData(255);  // C2 --> BLUE3
    send16bitData(0);    // A1 --> BLUE2
    send16bitData(255);  // B1 --> BLUE1
    // GREEN segment
    send16bitData(0);    // C1 --> GREEN8
    send16bitData(0);    // A0 --> GREEN7
    send16bitData(0);    // B0 --> GREEN6
    send16bitData(0);    // C0 --> GREEN5

    // second data segment for the 1nd MY9221 chip
    send16bitData(CmdMode);
    // GREEN segment
    send16bitData(0);    // A3 --> GREEN4
    send16bitData(0);    // B3 --> GREEN3
    send16bitData(0);    // C3 --> GREEN2
    send16bitData(0);    // A2 --> GREEN1
    // RED segment
    send16bitData(0);    // B2 --> RED8
    send16bitData(255);  // C2 --> RED7
    send16bitData(0);    // A1 --> RED6
    send16bitData(255);  // B1 --> RED5
    send16bitData(0);    // C1 --> RED4
    send16bitData(255);  // A0 --> RED3
    send16bitData(0);    // B0 --> RED2
    send16bitData(255);  // C0 --> RED1

    // data transfered and latch it
    latchData();

    // change the line. we have 8 lines. m_currentLine uses therefor 3 bits
    // A0, A1, A2 used consecutive ports. we can use the linenumber to switch the ports
    lineBits = ((m_currentLine) << DEC_A0); // DEC_A0 is the first pin
    DEC_PORT &=~ lineBits;
    DEC_PORT |= lineBits;

    // enable the decoder
    DEC_PORT |= _BV(DEC_E3);

    // increment line number and enable decoder
    m_currentLine++;
    if (8 >= m_currentLine) {
    	m_currentLine = 0;
    }
}
Exemple #7
0
void LEDBar::setCmdMode(void)
{
    send16bitData(0x0000);
}