Hello everybody.
i don't know how to use array pointer ,can you help me !
i downloaded shortened_Final_Code_A.ino , it works good .
But i don't understand these code ,can you explan for me .
Thankyou
for (byte i=0; i<fontrows; i++) {
*pDst = *pSrc; // populate the destination byte
pDst += 8; // go to next row on buffer
pSrc++; // go to next set of 8 pixels in character
}
and full codes:
// Arduino 1.0.5 UNO R3
// Connections to board
const byte latchPin=8;
const byte clockPin=12;
const byte data_R1=10;
const byte data_R2=11;
const byte en_74138=2;
const byte la_74138=3;
const byte lb_74138=4;
const byte lc_74138=5;
const byte ld_74138=6;
byte ScanRow = 0;
unsigned long counter;
//Insert message here ("message ")
const char message[] = "Tustin High School T-Tech Academy ";
// Routine to print a single character in one of 8 columns
// Inputs:
// x is one of (0,16,24,32,40,48,56),
// y (0 to 16 or 24 depending upon font size),
// n is either (0 to 9) or an ascii value,
// font=0 for big font, 2 for small font,
// inverse is true for an inverted character
void drawChar(uint16_t x, uint16_t y, byte n, byte font, boolean inverse) {
byte charbytes[16], fontrows, xover8 = x>>3;
int index;
if (0 != (x % 8)) return; // x not a multiple of 8
if ((n>9) && (n<32)) return; // invalid character
if (font==0) fontrows=16; else fontrows=8;
if ((n>=0) && (n<=9)) index=(n+16)*fontrows; else index=(n-32)*fontrows; // go to the right code for this character
// addressing start at buffer and add y (rows) * (WIDTH is 64 so WIDTH/8) is 8 plus (x / 8) is 0 to 7
byte *pDst = buffer + (y << 3) + xover8;
for (byte i=0;i<fontrows;i++) { // fill up the charbytes array with the right bits
if (font==0) charbytes = pgm_read_byte(&(font8x16_basic[index+i]));
- // reverse bit order for fonts 0 and 1*
- if (font != 0) {*
charbytes = (charbytes & 0xF0) >> 4 | (charbytes & 0x0F) << 4;
charbytes = (charbytes & 0xCC) >> 2 | (charbytes & 0x33) << 2;
charbytes = (charbytes & 0xAA) >> 1 | (charbytes & 0x55) << 1;
* };*
if (inverse) charbytes = ~charbytes*;*
* };*
_ const byte pSrc = charbytes; // point at the first set of 8 pixels
for (byte i=0; i<fontrows; i++) {
pDst = pSrc; // populate the destination byte_
_ pDst += 8; // go to next row on buffer
pSrc++; // go to next set of 8 pixels in character*
* }
};
void moveLeft(byte pixels, byte rowstart, byte rowstop) { // routine to move certain rows on the screen "pixels" pixels to the left
byte row, column;
short unsigned int address;
for (column=0;column<8;column++) {
for (row=rowstart;row<rowstop;row++) {
address = (row<<3) + column; /// right here!
if (column==7)
buffer[address] = buffer[address]<<pixels; // shuffle pixels left on last column and fill with a blank*
* else { // shuffle pixels left and add leftmost pixels from next column*
* byte incomingchar = buffer[address+1];
buffer[address] = buffer[address]<<pixels;
for (byte x=0;x<pixels;x++) { buffer[address] += ((incomingchar & (128>>x)) >> (7-x))<<(pixels-x-1); };
}
}
}
};
void shiftOut(byte row) { // fast routine to shove out 8 columns into two rows via board's shift registers
for(byte column=0;column<8;column++) {
byte index = column + (row<<3);
for(byte i=0;i<8;i++) { _
PORTB &=~(3<<(data_R1-8)); // data_R2 is LOW; data_R1 is LOW;
_ PORTB &=~(1<<(clockPin-8)); // digitalWrite(clockPin,LOW);_
PORTB |= !((buffer[index]>>(7-i)) & 0x01) << (data_R1-8); // top set of rows*
* PORTB |= !((buffer[index+128]>>(7-i)) & 0x01) << (data_R2-8); // bottom set of rows*
* PORTB |= 1<<(clockPin-8); // digitalWrite(clockPin,HIGH);*
* };*
* };*
};
ISR(TIMER2_COMPA_vect){
_ cli();
* digitalWrite(en_74138, HIGH); // Turn off display*
* shiftOut(ScanRow); // Shift out 8 columns*
* digitalWrite(latchPin, LOW);
digitalWrite(latchPin, HIGH);_
PORTD = (ScanRow << 3) | (PORTD & 0X87); // Highlight row: pins 3 4 5 6 (la_74138 lb_74138 lc_74138 ld_74138)
digitalWrite(en_74138, LOW); // Turn on display*
* ScanRow++; // Do the next pair of rows next time this routine is called*
* if (ScanRow==16) ScanRow=0;*
* sei();*
};
void setup() {
// Set up Timer2 as the 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 pairs of rows)*
_ OCR2A = 97; // 97 = (16,000,000 / (1024160)) - 1_
_ TCCR2A |= (1 << WGM21); TIMSK2 |= (1 << OCIE2A);*_
* pinMode(latchPin,OUTPUT); pinMode(clockPin,OUTPUT);*
* pinMode(data_R1,OUTPUT); pinMode(data_R2,OUTPUT);*
* pinMode(en_74138,OUTPUT);
pinMode(la_74138,OUTPUT); pinMode(lb_74138,OUTPUT);
pinMode(lc_74138,OUTPUT); pinMode(ld_74138,OUTPUT);*
* digitalWrite(en_74138, LOW);
digitalWrite(data_R1, HIGH); digitalWrite(data_R2, HIGH);
_ counter = millis();
sei(); //allow interrupts*
};
*void loop() { *
static int count=0;_
// display next character of message
* drawChar(56,16,message[count%(sizeof(message)-1)],0,false);*
* count = (count + 1);*
* // move the text 7 pixels (not 8 because it looks better) to the left*
* for (byte i=0; i<4; i++) {*
* delay(80);*
* moveLeft(2,1,32);*
* };*
};