Quick demo for LED 8x8 Matrix with FRDM-K82F

/media/uploads/suntopbd/img_20180523_081229.jpg

main.cpp

Committer:
suntopbd
Date:
2018-05-23
Revision:
0:b16b3c2d882e
Child:
1:1088a4658fc2

File content as of revision 0:b16b3c2d882e:

// copyleft by suntopbd 23.5.18
/*
PINOUT
https://os.mbed.com/platforms/FRDM-K82F/#board-pinout
should work with any other board with 16 I/O available
    
    C1 C2 C3 C4 C5 C6 C7 C8
R1   x  x  x  x  x  x  x  x
R2   x  x  x  x  x  x  x  x
R3   x  x  x  x  x  x  x  x
R4   x  x  x  x  x  x  x  x
R5   x  x  x  x  x  x  x  x
R6   x  x  x  x  x  x  x  x
R7   x  x  x  x  x  x  x  x
R8   x  x  x  x  x  x  x  x

*/
#include "mbed.h"

// Row Pins //
DigitalOut R1(PTC9);
DigitalOut R2(PTC8);
DigitalOut R3(PTC10);
DigitalOut R4(PTC11);
DigitalOut R5(PTA14);
DigitalOut R6(PTC7);
DigitalOut R7(PTA16);
DigitalOut R8(PTA15);

// Col Pins //
DigitalOut C1(PTD0);
DigitalOut C2(PTC12);
DigitalOut C3(PTB17);
DigitalOut C4(PTB16);
DigitalOut C5(PTA5);
DigitalOut C6(PTA13);
DigitalOut C7(PTA12);
DigitalOut C8(PTA17);

// func declearation //

void disp_off(void);
void disp_line(int,int,int,int,int,int,int,int,int);
void disp_page(int*);

 
int *dotpointer;

// 0 will glow LED and 1 will keep off //
// Use it to make Icon, Character, Symble //
int canvas[64] = { 

  0,1,1,1,1,1,1,0,
  1,1,0,1,1,0,1,1,
  1,0,1,1,1,1,0,1,
  1,1,1,0,0,1,1,1,
  1,1,1,0,0,1,1,1,
  1,1,0,1,1,0,1,1,
  1,0,1,1,1,1,0,1,  
  0,1,1,1,1,1,1,0,  

};  

EventQueue refresh_disp;
void update_disp();


int main() {
// SETUP //
 disp_off();
 refresh_disp.call_every(.5, update_disp);
 refresh_disp.dispatch();   
    
// END OF SETUP //
    

// LOOP //
    while (1) 
    {
    }
// END OF LOOP //
}

//..........................................//


// MBED OS Tasks //
void update_disp()
{
    dotpointer = &canvas[0];
    disp_page(dotpointer);
    disp_off();
    
}

// End of Tasks //


// Functions Body //
void disp_off(void)
{
// for CC type    
C1 = 1; C2 = 1; C3 = 1; C4 = 1; C5 = 1; C6 = 1; C7 = 1; C8 = 1;    
// for CA 
//C1 = 0; C2 = 0; C3 = 0; C4 = 0; C5 = 0; C6 = 0; C7 = 0; C8 = 0;    
}

void disp_line(int r,int c1,int c2,int c3,int c4,int c5,int c6,int c7,int c8)
{
    disp_off();
    if(r==1) {R1=1;R2=0;R3=0;R4=0;R5=0;R6=0;R7=0;R8=0;}
    if(r==2) {R1=0;R2=1;R3=0;R4=0;R5=0;R6=0;R7=0;R8=0;}
    if(r==3) {R1=0;R2=0;R3=1;R4=0;R5=0;R6=0;R7=0;R8=0;}
    if(r==4) {R1=0;R2=0;R3=0;R4=1;R5=0;R6=0;R7=0;R8=0;}
    if(r==5) {R1=0;R2=0;R3=0;R4=0;R5=1;R6=0;R7=0;R8=0;}
    if(r==6) {R1=0;R2=0;R3=0;R4=0;R5=0;R6=1;R7=0;R8=0;}
    if(r==7) {R1=0;R2=0;R3=0;R4=0;R5=0;R6=0;R7=1;R8=0;}
    if(r==8) {R1=0;R2=0;R3=0;R4=0;R5=0;R6=0;R7=0;R8=1;}
    C1=c1;C2=c2;C3=c3;C4=c4; C5=c5;C6=c6;C7=c7;C8=c8;
}



void disp_page(int *dot)
{
  disp_line(1,*(dot+0) ,*(dot+1) ,*(dot+2) ,*(dot+3) ,*(dot+4) ,*(dot+5) ,*(dot+6) ,*(dot+7) );
  disp_line(2,*(dot+8) ,*(dot+9) ,*(dot+10),*(dot+11),*(dot+12),*(dot+13),*(dot+14),*(dot+15));
  disp_line(3,*(dot+16),*(dot+17),*(dot+18),*(dot+19),*(dot+20),*(dot+21),*(dot+22),*(dot+23));
  disp_line(4,*(dot+24),*(dot+25),*(dot+26),*(dot+27),*(dot+28),*(dot+29),*(dot+30),*(dot+31));
  disp_line(5,*(dot+32),*(dot+33),*(dot+34),*(dot+35),*(dot+36),*(dot+37),*(dot+38),*(dot+39));
  disp_line(6,*(dot+40),*(dot+41),*(dot+42),*(dot+43),*(dot+44),*(dot+45),*(dot+46),*(dot+47));
  disp_line(7,*(dot+48),*(dot+49),*(dot+50),*(dot+51),*(dot+52),*(dot+53),*(dot+54),*(dot+55));
  disp_line(8,*(dot+56),*(dot+57),*(dot+58),*(dot+59),*(dot+60),*(dot+61),*(dot+62),*(dot+63));

}

// End of Functions //