Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
int dataPin = 2; // ic: 14, ser_in Define which pins will be used for the Shift Register control
int latchPin = 3; // ic:12 silkscreen numbers!
int clockPin = 4;
char displayPointer=0; // for interrupt use...
static char font [80] = //numbers stored here
{
0x00, 0x7c, 0xa2, 0x92, 0x8a, 0x7c, 0x00, 0x00, // 0
0x00, 0x42, 0xfe, 0x02, 0x00, 0x00, 0x00, 0x00, // 1
0x00, 0x42, 0x86, 0x8a, 0x92, 0x62, 0x00, 0x00, // 2
0x00, 0x84, 0x82, 0xa2, 0xd2, 0x8c, 0x00, 0x00, // 3
0x00, 0x18, 0x28, 0x48, 0xfe, 0x08, 0x00, 0x00, // 4
0x00, 0xe4, 0xa2, 0xa2, 0xa2, 0x9c, 0x00, 0x00, // 5
0x00, 0x3c, 0x52, 0x92, 0x92, 0x0c, 0x00, 0x00, // 6
0x00, 0x80, 0x8e, 0x90, 0xa0, 0xc0, 0x00, 0x00, // 7
0x00, 0x6c, 0x92, 0x92, 0x92, 0x6c, 0x00, 0x00, // 8
0x00, 0x60, 0x92, 0x92, 0x94, 0x78, 0x00, 0x00, // 9
};
unsigned char buffer[32]; // buffer for screen
unsigned char backbuffer[32]; // Spare screen for drawing on
char power[8]={128,64,32,16,8,4,2,1};
ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
{
unsigned char columndata;
unsigned char columnnumber;
if(TIFR2) // Make sure its the timer interrupt.
{
columndata= buffer[displayPointer]; // 32 bits of column
columnnumber = displayPointer;
setcolumn(columnnumber);
setdata(columndata);
digitalWrite(latchPin ,HIGH);digitalWrite(latchPin , LOW ); // STORECLOCK
if(++displayPointer==32) { displayPointer = 0; } // 32 LED row sections in total
}
TIFR2 = 0; // Clear timer 2 interrupt flag
}
void setcolumn(unsigned char col){
unsigned char pos;
col++;
for (pos = 33;pos>0;pos--){
if (col == pos){digitalWrite(dataPin ,HIGH);}else {digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,LOW);
}}
void setdata(unsigned char dat){
unsigned char pos;
for (pos = 0;pos<8;pos++){
if (dat & 128){dat-=128;digitalWrite(dataPin ,HIGH);}else { digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
dat = dat * 2;
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,LOW);
}}
void pixel(signed char x,signed char y,int cond)
{
int tmp;
char pix,msk;
if(x<0 || y<0) return; // outside drawing limits negative
if(x>31 || y>7) return; // outside drawing limits positive
pix = power[y];
msk = backbuffer[x]; // get exsisting data
if(cond == 2) { pix ^= msk; } // XOR data to screen
if (cond == 1) { pix = ~pix; pix &= msk; } // AND data to screen
if(cond == 0) { pix |= msk; } // OR data to screen
backbuffer[tmp] = pix; // apply changes
}
void charput(char ch, signed char x,signed char y)
{
signed char x1, y1;
const char* addr2; // pointer to character
char disp;
ch -= 0x20; // characters starts a 0 not 0x20
addr2 = &font[0]; // start of font array
addr2 = addr2 + ((int)ch * 8); // start place in font array
for( y1=0;y1<8;y1++) // eight rows
{
disp = *addr2;
for (x1 = 0; x1<8; x1++) // eight pixels
{
if(disp & power[x1])
pixel(x+x1,y+y1,0); // OR the pixel to the display buffer
}
addr2++;
}
}
void strput(const char* ch, signed char x,signed char y)
{
int addr;
while (*ch )
{
charput(*ch++,x,y); // write a string to the display buffer
x+=7;
}
}
void clr() //clear
{
int addr;
for(addr=0;addr<32;addr++) // Empty display buffer
backbuffer[addr]= 0;
}
void Blit() //transfers data between display buffer to screen buffer
{
int addr=0;
noInterrupts(); // disable all interrupts during setup
for(addr=0;addr < 32;addr ++)
{
buffer[addr] = backbuffer[addr]; // put all data from display buffer
} // to screen buffer
interrupts(); // enable all interrupts
}
void displaystring(void) // this routine prints through the screen buffer
{ // moving one pixel at a time
signed char x=32,y=0; // I made these signed so I could print
for(y = 0;y < 32 ;y++) // to nowhere so I could produce the scrolling effect
{
clr(); // Clear the display buffer
pixel(1,1,0);pixel(1,2,0);
pixel(2,1,0);pixel(2,2,0);
pixel(3,3,1);pixel(3,4,1);
pixel(4,4,2);pixel(4,5,2);
Blit(); // pass to screen buffer
delay(500); // time to view
}
}
void setup() //setup runs once
{
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions
//int sx,sy; //these two necessary? couldn't see them anywhere else than ball-thingy
//int xdir=1, ydir=1;
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 31250; // compare match register 16MHz/256/2Hz
TCCR1B |= (1 << WGM12); // CTC mode, free-running, clear on match
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
interrupts(); // enable all interrupts
displaystring(); //prints just hello world at startup
while(1) //essentially loop()? but loop is still needed...
{
clr(); //clear buffer first
/*sx += xdir; sy += ydir; no balls needed so can be omitted
strput("]",sx,sy); // this is a ball character for bouncing routine
if(sx>27) xdir = -1; /// Wall limits
if(sy>4) ydir = -1;
if(sx<0) xdir = 1;
if(sy<0) ydir = 1;*/
delay(80); //delay, but won't effect ISR
Blit(); //swap buffers
}
} // End main
void loop() //just sitting here
{}
^this line? or does it blew up timer sequence? At least when I have done so, at first it does go well but in certain value nothing is drawn in screen.OCR1A = 31250; // compare match register 16MHz/256/2Hz
umm, no :/was post 130 able to light up in the corners? (bottom left & top right)?
Arduino: 1.6.5 (Windows 7), Board: "Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)"
sketch_jan15a.ino: In function 'void charput(char, signed char, signed char)':
sketch_jan15a:96: error: invalid conversion from 'char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]
invalid conversion from 'char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.