96 * 16 led dot matrix problem


can arduino sketch? display 12 characters using 96 *16 dot matrix ((16*16 matrix)*6)

in attached sketch. fifth matrix , sixth matrix display 9~ 12 characters ,  1~4 characters alternatively.

ex:) message " abcdefghijkl" ................... ijkl, abcd alternatively

i display matrix 2 function. first displaying fixed characters, seond scrolling right left.

first.  it must resolve fifth , sixth matrix alternatively display.

i attacted fifth , sixth matrix displaying ijkl , abcd. wanna display ijkl

and if scrolling right left, how can modify sketch?

thank you


sketch file , matrix image files atttaced..

#include <avr/pgmspace.h>
#include "pins_arduino.h"
// based on mymatrix arduino library
// silviu - www.openhardware.ro
// mit license (mit)
// connections board

const byte pinstb=9;
const byte pinclock=8;
const byte pinred=6;
const byte pingreen=7;
const byte pinoe=10;
const byte pinrowa=2;
const byte pinrowb=3;
const byte pinrowc=4;
const byte pinrowd=5;
byte scanrow = 0;
unsigned long counter;

//insert message here ("message ")
char message[] = "abcdefghijklmnopqrstuvw";

// ---------------------------------------------------------------------------------------------------
const byte red    = 0b01;
const byte green  = 0b10;
const byte yellow = 0b00;
const byte black  = 0b11;

struct color {
byte r;
byte g;
};



#define buffer_init_256 buffer_init_100 buffer_init_10 buffer_init_10 buffer_init_8
#define buffer_init_100 buffer_init_50 buffer_init_50
#define buffer_init_50  buffer_init_10 buffer_init_10 buffer_init_10 buffer_init_10 buffer_init_10
#define buffer_init_10  buffer_init_2 buffer_init_2 buffer_init_2 buffer_init_2 buffer_init_2
#define buffer_init_8   buffer_init_2 buffer_init_2 buffer_init_2 buffer_init_2
#define buffer_init_2   buffer_init_1 buffer_init_1
#define buffer_init_1   {0x00, 0x00},

color buffer[256] = {buffer_init_256};



// ---------------------------------------------------------------------------------------------------

// fonts sourced various locations on internet
// full ascii character set (8x16) (1520 bytes)

static const uint8_t font16x16_basic[][16] progmem = {



// function colorize pixel
// color 2 bit, (r)ed (g)reen 0b000000rg

void setpixel(uint8_t x ,uint8_t y, uint8_t color) //uint8_t =byte (x, y, color)

{
byte myindex;   // oringin(y+x/8;8 segments per row
byte mybitmask;

{
myindex = (y*8)+x/8;
 mybitmask = 7 -(x % 8);
bitwrite(buffer[myindex].r, mybitmask, (color& 0b00000010));  // buffer(),r = x, mybitmask = n
bitwrite(buffer[myindex].g, mybitmask, (color& 0b00000001));
}


}

// function print character @ column
// means text starts in upper left corner
void printchar(uint8_t x_offset, uint8_t fg_color, uint8_t bg_color, byte ch) {

if (0 != (x_offset % 8)) return;    // x_offset not multiple of 8
if ((ch>9) && (ch<32)) return; // invalid character
const uint8_t y_offset = 0;
for (uint8_t y=0; y<16; y++){
for (uint8_t i=0; i<8; i++){
 if(bitread(pgm_read_byte(&font16x16_basic[ch-32][y]),i)) setpixel(x_offset+i, y_offset+y, fg_color);          
 else setpixel(x_offset+i, y_offset+y, bg_color);
     }
}

}


// function scrol text message left

void hscroll(uint8_t fg_color, uint8_t bg_color, char *mystring)
{
// offset starts 0
// means text starts in upper left corner
// serial.println(lenstring(mystring));

for (int offset= ((lenstring(mystring)-8)*8-1); offset >0 ; offset--) {
for (byte x=0; x<96; x++){
 for (byte y=0; y<16; y++){
   byte color=bg_color;
   if (getpixelmessage(x,y,mystring)) color=fg_color;
   setpixel(x,y,color);
    }
   }
delay(40);  
  }
 }

byte getpixelmessage(uint8_t x, uint8_t y, char *p){
  p=p+x/8;

return getpixelchar(x%8, y, *p);
}


byte getpixelchar(byte x, uint8_t y, char ch){

 return bitread(pgm_read_byte(&font16x16_basic[ch-32][y]),x);
}

// length of message string

uint8_t lenstring(char *p){
unsigned int retval=0;
while(*p!='\0'){
retval++;
p++;

}
return retval;
}



void clearscreen(){
for (uint8_t i=0; i<256; i++)  // buffer size
{
 buffer.r=0;
 buffer.g=0;
delay (2);
}
}
// helper function paint 1 row
void shiftout(uint8_t row) {
const uint8_t bitred = digitalpintobitmask(pinred);
volatile uint8_t *outred = portoutputregister(digitalpintoport(pinred));

const uint8_t bitgreen = digitalpintobitmask(pingreen);
volatile uint8_t *outgreen = portoutputregister(digitalpintoport(pingreen));

const uint8_t bitclock = digitalpintobitmask(pinclock);
volatile uint8_t *outclock = portoutputregister(digitalpintoport(pinclock));

const uint8_t bitrowa = digitalpintobitmask(pinrowa);
volatile uint8_t *outrowa = portoutputregister(digitalpintoport(pinrowa));

const uint8_t bitrowb = digitalpintobitmask(pinrowb);
volatile uint8_t *outrowb = portoutputregister(digitalpintoport(pinrowb));

const uint8_t bitrowc = digitalpintobitmask(pinrowc);
volatile uint8_t *outrowc = portoutputregister(digitalpintoport(pinrowc));

const uint8_t bitrowd = digitalpintobitmask(pinrowd);
volatile uint8_t *outrowd = portoutputregister(digitalpintoport(pinrowd));

const uint8_t bitoe = digitalpintobitmask(pinoe);
volatile uint8_t *outoe = portoutputregister(digitalpintoport(pinoe));

const uint8_t bitstb = digitalpintobitmask(pinstb);
volatile uint8_t *outstb = portoutputregister(digitalpintoport(pinstb));  



*outoe |= bitoe;  // turn off display  // digitalwrite(pinoe,high);

// select row

if (bitread(row, 0)) *outrowa |= bitrowa; else *outrowa &= ~bitrowa;
if (bitread(row, 1)) *outrowb |= bitrowb; else *outrowb &= ~bitrowb;
if (bitread(row, 2)) *outrowc |= bitrowc; else *outrowc &= ~bitrowc;
if (bitread(row, 3)) *outrowd |= bitrowd; else *outrowd &= ~bitrowd;
 
for(uint8_t column=0; column<12; column++){  // 8 segments
uint8_t index = column + (row*8);  // 8 segments
for(uint8_t i=0; i<8; i++) {

 if (buffer[index].r & (1<<(7-i))) *outred &= ~bitred;
 else *outred |= bitred;
 if (buffer[index].g & (1<<(7-i))) *outgreen &= ~bitgreen;
 else *outgreen |= bitgreen;

   //clock pulse

 *outclock |= bitclock; //clk, high
 *outclock &= ~bitclock; //clk, low

}

}

*outstb &= ~bitstb;  // digitalwrite(pinstb,low);
*outstb |= bitstb;   // digitalwrite(pinstb,high);
*outoe &= ~bitoe;    // turn on display  // digitalwrite(pinoe,low);

}

// interrupt routine responsible painting screen

isr(timer2_compa_vect){

cli();
shiftout(scanrow);
if (scanrow < 15) scanrow++; else scanrow = 0;
sei();
}

void setup() {

// use timer2 scanning interrupt timer

cli(); // clear interrupts

tccr2a = 0; tccr2b = 0; tcnt2  = 0;
tccr2b |= (1 << cs12) | (1 << cs10);     // set 1024 prescaler
          // 160hz scan rate = 10 frames/second (16 rows)
ocr2a = 97;  // 97 = (16,000,000 / (1024*160)) - 1
tccr2a |= (1 << wgm21); timsk2 |= (1 << ocie2a);

pinmode(pinred, output);
pinmode(pingreen, output);
pinmode(pinclock, output);
pinmode(pinrowa, output);
pinmode(pinrowb, output);
pinmode(pinrowc, output);
pinmode(pinrowd, output);
pinmode(pinoe, output);
pinmode(pinstb, output);
digitalwrite(pinoe, low);
digitalwrite(pinred, high); digitalwrite(pingreen, high);
sei(); //allow interrupts

serial.begin(9600);
}

// main loop responsible updating screen
void loop() {  
//  printchar(0,green,black,'a');
hscroll(red, black, message);

}

if want help, must first read this, points 7 & 9. fix post above.


Arduino Forum > Using Arduino > LEDs and Multiplexing > 96 * 16 led dot matrix problem


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor