yes, they do blink & change thankfully. I played bit and managed to make scrolling counter with millis(), so RTC should be indeed possible!I am worried though that you cant see scrolling, what about the binary values in the corner, they should be changing with time?
#include "FontMap.h"
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
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;
unsigned char displayPointer = 0; // for interrupt use...
unsigned char buffer1[32]; // buffer for screen
unsigned char backbuffer[32]; // Spare screen for drawing on
unsigned char power[8] = {128, 64, 32, 16, 8, 4, 2, 1};
ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine, called every now and then, outside of loop
{
if (TIFR2) // Make sure its the timer interrupt.
{
setcolumn(displayPointer); //column scanning
setdata(buffer1[displayPointer]);
PORTD = (1 << PORTD3);
PORTD = (0 << PORTD3);
//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) //loop that takes care of column scanning
{
signed char pos;
for (pos = 32; pos > -1; pos--)
{
if (col == pos)
{
PORTD = (1 << PORTD2);
//digitalWrite(dataPin ,HIGH);
}
else
{
PORTD = (0 << PORTD2);
//digitalWrite(dataPin ,LOW);
} // PIN1 DATA pin
//PORTD=(1<<PORTD4);
//PORTD=(0<<PORTD4);
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;
PORTD = (1 << PORTD2);
//digitalWrite(dataPin ,HIGH);
}
else
{
PORTD = (0 << PORTD2);
}
//digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
dat = dat * 2;
digitalWrite(clockPin , HIGH);
digitalWrite(clockPin , LOW);
}
}
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 ++)
{
buffer1[addr] = backbuffer[addr]; // put all data from display buffer
} // to screen buffer
interrupts(); // enable all interrupts
}
void pixel(signed char x, signed char y, int cond)
{
unsigned 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[x] = pix; // apply changes
}
void charput(unsigned char ch, signed char x, signed char y)
{
signed char x1, y1;
unsigned char disp;
unsigned char disp2;
for ( x1 = 0; x1 < 8; x1++) // eight rows
{
disp = font[x1 + (ch * 8)];
for (y1 = 0; y1 < 8; y1++) // eight pixels
{
disp2 = disp & power[y1];
if (disp2 > 0)
{
pixel(x + x1, y + y1, 0); // OR the pixel to the display buffer
}
}
}
}
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 setup() //setup runs once
{
Wire.begin();
RTC.begin();
signed char cntr;
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 31; // compare match register 16MHz/256/2Hz -----------------------------------> delay time (lcd flicker/brightness)
TCCR1B |= (1 << WGM12); // CTC mode, free-running, clear on match
TCCR1B |= (0 << CS10); // 256 prescaler
TCCR1B |= (0 << CS11); // 256 prescaler
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
interrupts(); // enable all interrupts
} // End main
void loop() //just sitting here
{
DateTime now = RTC.now();
signed char scrollctr;
for (scrollctr = 112; scrollctr > -8; scrollctr--)
{
clr();
charput(((now.day() / 10) % 10), scrollctr - 80, 0);
charput(((now.day() / 1) % 10), scrollctr - 72, 0);
strput("/", scrollctr - 64, 0);
charput(((now.month() / 10) % 10), scrollctr - 56, 0);
charput(((now.month() / 1) % 10), scrollctr - 48, 0);
strput("/", scrollctr - 40, 0);
charput(((now.year() / 1000) % 10), scrollctr - 32, 0);
charput(((now.year() / 100) % 10), scrollctr - 24, 0);
charput(((now.year() / 10) % 10), scrollctr - 16, 0);
charput(((now.year() / 1) % 10), scrollctr - 8, 0);
Blit();
delay(100);
}
for (scrollctr = 96; scrollctr > -8; scrollctr--)
{
clr();
charput(((now.hour() / 10) % 10), scrollctr - 64, 0);
charput(((now.hour() / 1) % 10), scrollctr - 56, 0);
strput(":", scrollctr - 48, 0);
charput(((now.minute() / 10) % 10), scrollctr - 40, 0);
charput(((now.minute() / 1) % 10), scrollctr - 32, 0);
strput(":", scrollctr - 24, 0);
charput(((now.second() / 10) % 10), scrollctr - 16, 0);
charput(((now.second() / 1) % 10), scrollctr - 8, 0);
Blit();
delay(100);
}
}
static unsigned char font [1000] = //numbers stored here
{ //Position, Character
0x00, 0x00, 0x7E, 0x81, 0x81, 0x81, 0x7E, 0x00, // 0 0
0x00, 0x00, 0x80, 0x82, 0xFF, 0x80, 0x80, 0x00, // 1 1
0x00, 0x00, 0xC2, 0xA1, 0x91, 0x89, 0x86, 0x00, // 2 2
0x00, 0x00, 0x42, 0x91, 0x91, 0x91, 0x6E, 0x00, // 3 3
0x00, 0x00, 0x18, 0x14, 0x12, 0xFF, 0x10, 0x00, // 4 4
0x00, 0x00, 0x4F, 0x91, 0x91, 0x91, 0x61, 0x00, // 5 5
0x00, 0x00, 0x6E, 0x91, 0x91, 0x91, 0x62, 0x00, // 6 6
0x00, 0x00, 0x01, 0xF1, 0x09, 0x05, 0x03, 0x00, // 7 7
0x00, 0x00, 0x6E, 0x91, 0x91, 0x91, 0x6E, 0x00, // 8 8
0x00, 0x00, 0x8E, 0x91, 0x91, 0x91, 0x6E, 0x00, // 9 9
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, // 10
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, // 11
0x81, 0x42, 0x00, 0x18, 0x18, 0x00, 0x42, 0x01, // 12
0x00, 0x84, 0x82, 0xa2, 0xd2, 0x8c, 0x00, 0x00, // 13
0x00, 0x18, 0x28, 0x48, 0xfe, 0x08, 0x00, 0x00, // 14
0x00, 0xe4, 0xa2, 0xa2, 0xa2, 0x9c, 0x00, 0x00, // 15
0x00, 0x3c, 0x52, 0x92, 0x92, 0x0c, 0x00, 0x00, // 16
0x00, 0x80, 0x8e, 0x90, 0xa0, 0xc0, 0x00, 0x00, // 17
0x00, 0x6c, 0x92, 0x92, 0x92, 0x6c, 0x00, 0x00, // 18
0x00, 0x60, 0x92, 0x92, 0x94, 0x78, 0x00, 0x00, // 19
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, // 20
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, // 21
0x81, 0x42, 0x00, 0x18, 0x18, 0x00, 0x42, 0x01, // 22
0x00, 0x84, 0x82, 0xa2, 0xd2, 0x8c, 0x00, 0x00, // 23
0x00, 0x18, 0x28, 0x48, 0xfe, 0x08, 0x00, 0x00, // 24
0x00, 0xe4, 0xa2, 0xa2, 0xa2, 0x9c, 0x00, 0x00, // 25
0x00, 0x3c, 0x52, 0x92, 0x92, 0x0c, 0x00, 0x00, // 26
0x00, 0x80, 0x8e, 0x90, 0xa0, 0xc0, 0x00, 0x00, // 27
0x00, 0x6c, 0x92, 0x92, 0x92, 0x6c, 0x00, 0x00, // 28
0x00, 0x60, 0x92, 0x92, 0x94, 0x78, 0x00, 0x00, // 29
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, // 30
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, // 31
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 32 "space"
0x00, 0x00, 0x00, 0xFB, 0xFB, 0x00, 0x00, 0x00, // 33 !
0x00, 0x18, 0x28, 0x48, 0xfe, 0x08, 0x00, 0x00, // 34
0x00, 0xe4, 0xa2, 0xa2, 0xa2, 0x9c, 0x00, 0x00, // 35
0x00, 0x3c, 0x52, 0x92, 0x92, 0x0c, 0x00, 0x00, // 36
0x00, 0x80, 0x8e, 0x90, 0xa0, 0xc0, 0x00, 0x00, // 37
0x00, 0x6c, 0x92, 0x92, 0x92, 0x6c, 0x00, 0x00, // 38
0x00, 0x60, 0x92, 0x92, 0x94, 0x78, 0x00, 0x00, // 39
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, // 40
0x00, 0x81, 0x21, 0xC1, 0xFF, 0x01, 0x01, 0x00, // 41
0x81, 0x42, 0x00, 0x18, 0x18, 0x00, 0x42, 0x01, // 42
0x00, 0x84, 0x82, 0xa2, 0xd2, 0x8c, 0x00, 0x00, // 43
0x00, 0x18, 0x28, 0x48, 0xfe, 0x08, 0x00, 0x00, // 44
0x00, 0xe4, 0xa2, 0xa2, 0xa2, 0x9c, 0x00, 0x00, // 45
0x00, 0x3c, 0x52, 0x92, 0x92, 0x0c, 0x00, 0x00, // 46
0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, // 47 /
0x00, 0x00, 0x7E, 0x81, 0x81, 0x81, 0x7E, 0x00, // 0 0
0x00, 0x00, 0x80, 0x82, 0xFF, 0x80, 0x80, 0x00, // 1 1
0x00, 0x00, 0xC2, 0xA1, 0x91, 0x89, 0x86, 0x00, // 2 2
0x00, 0x00, 0x42, 0x91, 0x91, 0x91, 0x6E, 0x00, // 3 3
0x00, 0x00, 0x18, 0x14, 0x12, 0xFF, 0x10, 0x00, // 4 4
0x00, 0x00, 0x4F, 0x91, 0x91, 0x91, 0x61, 0x00, // 5 5
0x00, 0x00, 0x6E, 0x91, 0x91, 0x91, 0x62, 0x00, // 6 6
0x00, 0x00, 0x01, 0xF1, 0x09, 0x05, 0x03, 0x00, // 7 7
0x00, 0x00, 0x6E, 0x91, 0x91, 0x91, 0x6E, 0x00, // 8 8
0x00, 0x00, 0x8E, 0x91, 0x91, 0x91, 0x6E, 0x00, // 9 9
0x00, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, // 58 :
0x00, 0x60, 0x92, 0x92, 0x94, 0x78, 0x00, 0x00, // 59
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, // 60
0x00, 0x81, 0x21, 0xC1, 0xFF, 0x01, 0x01, 0x00, // 61
0x81, 0x42, 0x00, 0x18, 0x18, 0x00, 0x42, 0x01, // 62
0x00, 0x84, 0x82, 0xa2, 0xd2, 0x8c, 0x00, 0x00, // 63
0x00, 0x18, 0x28, 0x48, 0xfe, 0x08, 0x00, 0x00, // 64
0x00, 0x00, 0X7C, 0X0A, 0X0A, 0X0A, 0X7C, 0x00, // 65 A
//0x94,0x5c,0xb6,0x5f,0x5f,0xb6,0x5c,0x94,
0x00, 0x00, 0x7E, 0x4A, 0x4A, 0x4A, 0x34, 0x00, // 66 B
0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, 0x24, 0x00, // 67 C
0x00, 0x00, 0x7E, 0x42, 0x42, 0x42, 0x3C, 0x00, // 68 D
0x00, 0x00, 0x7E, 0x4A, 0x4A, 0x4A, 0x4A, 0x00, // 69 E
0x00, 0x00, 0xFF, 0x11, 0x11, 0x11, 0x01, 0x00, // 70 F
0x00, 0x00, 0x3C, 0x42, 0x52, 0x52, 0x34, 0x00, // 71 G
0x00, 0x00, 0x7e, 0x10, 0x10, 0x10, 0x7e, 0x00, // 72 H
0x00, 0x00, 0x00, 0x42, 0x7e, 0x42, 0x00, 0x00, // 73 I
0x00, 0x00, 0x20, 0x40, 0x40, 0x3A, 0x00, 0x00, // 74 J
0x00, 0x00, 0x7E, 0x18, 0x24, 0x42, 0x00, 0x00, // 75 K
0x00, 0x00, 0x7E, 0x40, 0x40, 0x40, 0x40, 0x00, // 76 L
0x00, 0x00, 0x7E, 0x04, 0x08, 0x04, 0x7E, 0x00, // 77 M
0x00, 0x00, 0x7E, 0x04, 0x18, 0x20, 0x7E, 0x00, // 78 N
0x00, 0x00, 0x7E, 0x81, 0x81, 0x81, 0x7E, 0x00, // 79 O
0x00, 0x00, 0x7E, 0x0A, 0x0A, 0x0A, 0x04, 0x00, // 80 P
0x00, 0x00, 0x3C, 0x42, 0x52, 0x62, 0x3C, 0x00, // 81 Q
0x00, 0x00, 0x7C, 0x0A, 0x1A, 0x2A, 0x44, 0x00, // 82 R
0x00, 0x00, 0x24, 0x4A, 0x5A, 0x52, 0x24, 0x00, // 83 S
0x00, 0x00, 0x02, 0x02, 0x7E, 0x02, 0x02, 0x00, // 84 T
0x00, 0x00, 0x3E, 0x40, 0x40, 0x40, 0x3E, 0x00, // 85 U
0x00, 0x00, 0x1E, 0x20, 0x40, 0x20, 0x1E, 0x00, // 86 V
0x00, 0x00, 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x00, // 87 W
0x00, 0x00, 0x42, 0x24, 0x18, 0x24, 0x42, 0x00, // 88 X
0x00, 0x00, 0x02, 0x04, 0x78, 0x04, 0x02, 0x00, // 89 Y
0x00, 0x42, 0x62, 0x52, 0x4A, 0x46, 0x42, 0X00, // 90 Z
0x00, 0x81, 0x21, 0xC1, 0xFF, 0x01, 0x01, 0x00, // 91
0x81, 0x42, 0x00, 0x18, 0x18, 0x00, 0x42, 0x01, // 92
0x00, 0x84, 0x82, 0xa2, 0xd2, 0x8c, 0x00, 0x00, // 93
0x00, 0x18, 0x28, 0x48, 0xfe, 0x08, 0x00, 0x00, // 94
0x00, 0xe4, 0xa2, 0xa2, 0xa2, 0x9c, 0x00, 0x00, // 95
0x00, 0x3c, 0x52, 0x92, 0x92, 0x0c, 0x00, 0x00, // 96
0x00, 0x80, 0x8e, 0x90, 0xa0, 0xc0, 0x00, 0x00, // 97
0x00, 0x6c, 0x92, 0x92, 0x92, 0x6c, 0x00, 0x00, // 98
0x00, 0x60, 0x92, 0x92, 0x94, 0x78, 0x00, 0x00, // 99
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, // 100
0x00, 0x81, 0x21, 0xC1, 0xFF, 0x01, 0x01, 0x00, // 101
0x81, 0x42, 0x00, 0x18, 0x18, 0x00, 0x42, 0x01, // 102
0x00, 0x84, 0x82, 0xa2, 0xd2, 0x8c, 0x00, 0x00, // 103
0x00, 0x18, 0x28, 0x48, 0xfe, 0x08, 0x00, 0x00, // 104
0x00, 0x00, 0x00, 0x91, 0xBF, 0x01, 0x00, 0x00, // 105
0x00, 0x3c, 0x52, 0x92, 0x92, 0x0c, 0x00, 0x00, // 106
0x00, 0x80, 0x8e, 0x90, 0xa0, 0xc0, 0x00, 0x00, // 107
0x00, 0x6c, 0x92, 0x92, 0x92, 0x6c, 0x00, 0x00, // 108
0x00, 0x60, 0x92, 0x92, 0x94, 0x78, 0x00, 0x00, // 109
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, // 110
0x00, 0x81, 0x21, 0xC1, 0xFF, 0x01, 0x01, 0x00, // 111
0x81, 0x42, 0x00, 0x18, 0x18, 0x00, 0x42, 0x01, // 112
0x00, 0x84, 0x82, 0xa2, 0xd2, 0x8c, 0x00, 0x00, // 113
0x00, 0x18, 0x28, 0x48, 0xfe, 0x08, 0x00, 0x00, // 114
0x00, 0xe4, 0xa2, 0xa2, 0xa2, 0x9c, 0x00, 0x00, // 115
0x00, 0x3c, 0x52, 0x92, 0x92, 0x0c, 0x00, 0x00, // 116
0x00, 0x80, 0x8e, 0x90, 0xa0, 0xc0, 0x00, 0x00, // 117
0x00, 0x6c, 0x92, 0x92, 0x92, 0x6c, 0x00, 0x00, // 118
0x00, 0x60, 0x92, 0x92, 0x94, 0x78, 0x00, 0x00, // 119
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, // 120
0x00, 0x81, 0x21, 0xC1, 0xFF, 0x01, 0x01, 0x00, // 121
0x81, 0x42, 0x00, 0x18, 0x18, 0x00, 0x42, 0x01, // 122
0x00, 0x84, 0x82, 0xa2, 0xd2, 0x8c, 0x00, 0x00, // 123
0x00, 0x18, 0x28, 0x48, 0xfe, 0x08, 0x00, 0x00 // 124
};
Hehe, thanks Ian, that did the trick, now seconds update while scrollingMove this line into both for loops
DateTime now = RTC.now();
I think that's least think you can do after help!ohya, an ima steal that woof blit for myown youtube!
#include "FontMap7Segment.h"
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;
unsigned char displayPointer = 0; // for interrupt use...
unsigned char buffer1[4]; // buffer for screen, was 32 for matrix (4x8=32 and each character is built from 8x8 block, due 8x8 matrix) but for 7 segments, each character is 1x8 and screen is 4 digits so buffers are 4
unsigned char backbuffer[4]; // Spare screen for drawing on
unsigned char power[4] = {1, 2, 4, 8}; //B00000001,B00000010,B00000100,B00001000 for digits
// was: unsigned char power[8] = {128, 64, 32, 16, 8, 4, 2, 1};
ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine, called every now and then, outside of loop
{
if (TIFR2) // Make sure its the timer interrupt.
{
setcolumn(displayPointer); //column scanning
setdata(buffer1[displayPointer]);
PORTD = (1 << PORTD3);
PORTD = (0 << PORTD3);
//digitalWrite(latchPin ,HIGH);
//digitalWrite(latchPin , LOW ); // STORECLOCK
if (++displayPointer == 4) //was 32, now 4 as buffer sizes changed too
{ displayPointer = 0;
} // 32 LED row sections in total
}
TIFR2 = 0; // Clear timer 2 interrupt flag
}
void setcolumn(unsigned char col) //loop that takes care of column scanning
{
signed char pos;
for (pos = 4; pos > -1; pos--) //was pos=32, but again, only 4 columns now so pos=4
{
if (col == pos)
{
PORTD = (1 << PORTD2); //digitalWrite(dataPin ,HIGH);
}
else
{
PORTD = (0 << PORTD2); //digitalWrite(dataPin ,LOW);
}
digitalWrite(clockPin , HIGH);
digitalWrite(clockPin , LOW);
}
}
void setdata(unsigned char dat) {
unsigned char pos;
for (pos = 0; pos < 8; pos++)
{
if (dat & 16) //these dat were 128, but changed them to 16 as 16=128/8
{
dat -= 16;
PORTD = (1 << PORTD2); //digitalWrite(dataPin ,HIGH);
}
else
{
PORTD = (0 << PORTD2); //digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
}
dat = dat * 2;
digitalWrite(clockPin , HIGH);
digitalWrite(clockPin , LOW);
}
}
void clr() //clear
{
int addr;
for (addr = 0; addr < 4; addr++) // Empty display buffer, reduced from 32 to 4
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 < 4; addr ++) //here also changed 32 to 4
{
buffer1[addr] = backbuffer[addr]; // put all data from display buffer to screen buffer
}
interrupts(); // enable all interrupts
}
void pixel(signed char x, signed char y, int cond)
{
unsigned char pix, msk;
if (x < 0 || y < 0) return; // outside drawing limits negative
if (x > 3 || y > 7) return; // outside drawing limits positive, changed x>31 to x>3
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[x] = pix; // apply changes
}
void charput(unsigned char ch, signed char x, signed char y)
{
signed char x1, y1;
unsigned char disp;
unsigned char disp2;
for ( x1 = 0; x1 < 8; x1++) // eight rows, still eight bits to load so no changes
{
disp = font[x1 + (ch * 8)];
for (y1 = 0; y1 < 8; y1++) // eight pixels
{
disp2 = disp & power[y1];
if (disp2 > 0)
{
pixel(x + x1, y + y1, 0); // OR the pixel to the display buffer
}
}
}
}
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 setup() //setup runs once
{
signed char cntr;
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 260; // compare match register value, was 31 for matrix (1920hz= 60hzx*32) but for now there's only 4 columns so: 4*60hz=240hz; 16mhz/256/240=260
TCCR1B |= (1 << WGM12); // CTC mode, free-running, clear on match
TCCR1B |= (0 << CS10); // 256 prescaler
TCCR1B |= (0 << CS11); // 256 prescaler
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
interrupts(); // enable all interrupts
} // End main
void loop() //main loop
{
clr();
strput("0123", 0, 0); //test string to draw on segments
Blit();
}
#include "FontMap7Segment.h"
int dataPin = 2; //Define which pins will be used for the Shift Register control
int latchPin = 3;
int clockPin = 4;
boolean newData = false;
void setup()
{
Serial.begin(9600);
pinMode(dataPin, OUTPUT); //Configure each IO Pin
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
int i=Serial.read();
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
shiftOut(dataPin, clockPin, MSBFIRST, B00000001);
shiftOut(dataPin, clockPin, MSBFIRST, font[i]);
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(500);
}
Umm, how come cathodes straigth to ground? Aren't then all digits be on all the time and digits show same value?in this one you no longer need setcolumn routine, instead just delete setcolumn, and change setdata sub so it bumps out one numeric value after another..
also your cathodes can go straight to ground, with the 7 seg we no longer need to call them individually
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?