Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

(Solved)Again problem with matrix, this time 8x32

Status
Not open for further replies.
it would be interesting to see how option 2 impacts with overlays. (will fix in code next time)
much like the font encoder used here, i used GUI 's to encode , one string writer i did would take a bitmap image and convert to pixel strings for LCD screen(no Animation). the other was for CUBE which encoded frame by frame plus delay time for each.

is it wired up already on i2c, which pins?
if on I2C pins you could use i2c.h, which would be proper , but then i would become more spectator here! but better for professionalism!
OR*
I could bump out something that would basically work, customize-able to any I/O pin!

using this device we won't need more interrupts, looks simple enough;)
 
oh! very nice, yes, that code would be easy to integrate

.... except you may want to rewire shift register clock pin, hope you are on breadboard still!
 
Last edited:
Why would I need to switch clock pin for shift register? shift registers use digital pins 2,3,4 and RTC uses A4,A5 :)
 
K, lets give it a try!
note* it will take a bit longer to boot up , since RTC holds for the first 12 seconds to allow for programming, it will thank-you in terminal after boot delay

also change this in fontmap.h , note that it is to replace line 58.... 0x00, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, // 58 :

#include <Wire.h>
#include "FontMap.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;


const int DS1307 = 0x68; // Address of DS1307 see data sheets
const char* days[] =
{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const char* months[] =
{"January", "February", "March", "April", "May", "June", "July", "August","September", "October", "November", "December"};
// Initializes all values:
byte second = 0;
byte minute = 0;
byte hour = 0;
byte weekday = 0;
byte monthday = 0;
byte month = 0;
byte year = 0;


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
{
if(TIFR2) // Make sure its the timer interrupt.
{
setcolumn(displayPointer);
setdata(buffer1[displayPointer]);
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
}



byte decToBcd(byte val) {
return ((val/10*16) + (val%10));
}
byte bcdToDec(byte val) {
return ((val/16*10) + (val%16));
}


// This set of codes is allows input of data
void setTime() {
Serial.print("Please enter the current year, 00-99. - ");
year = readByte();
Serial.println(year);
Serial.print("Please enter the current month, 1-12. - ");
month = readByte();
Serial.println(months[month-1]);
Serial.print("Please enter the current day of the month, 1-31. - ");
monthday = readByte();
Serial.println(monthday);
Serial.println("Please enter the current day of the week, 1-7.");
Serial.print("1 Sun | 2 Mon | 3 Tues | 4 Weds | 5 Thu | 6 Fri | 7 Sat - ");
weekday = readByte();
Serial.println(days[weekday-1]);
Serial.print("Please enter the current hour in 24hr format, 0-23. - ");
hour = readByte();
Serial.println(hour);
Serial.print("Please enter the current minute, 0-59. - ");
minute = readByte();
Serial.println(minute);
second = 0;
Serial.println("The data has been entered.");
// The following codes transmits the data to the RTC
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(weekday));
Wire.write(decToBcd(monthday));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(byte(0));
Wire.endTransmission();
// Ends transmission of data
}


byte readByte() {
while (!Serial.available()) delay(10);
byte reading = 0;
byte incomingByte = Serial.read();
while (incomingByte != '\n') {
if (incomingByte >= '0' && incomingByte <= '9')
reading = reading * 10 + (incomingByte - '0');
else;
incomingByte = Serial.read();
}
Serial.flush();
return reading;
}


void printTime() {
char buffer[3];
const char* AMPM = 0;
readTime();
Serial.print(days[weekday-1]);
Serial.print(" ");
Serial.print(months[month-1]);
Serial.print(" ");
Serial.print(monthday);
Serial.print(", 20");
Serial.print(year);
Serial.print(" ");
if (hour > 12) {
hour -= 12;
AMPM = " PM";
}
else AMPM = " AM";
Serial.print(hour);
Serial.print(":");
sprintf(buffer, "%02d", minute);
Serial.print(buffer);
Serial.println(AMPM);
}


void readTime() {
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.endTransmission();
Wire.requestFrom(DS1307, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read());
weekday = bcdToDec(Wire.read());
monthday = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}


void setcolumn(unsigned char col){
signed char pos;
for (pos = 32;pos>-1;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 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;
}
}


unsigned char Vscroll(unsigned char value,unsigned char valueOL, signed char x,signed char y, unsigned char cntr1){ // Vscroll(hour, hourLA, x,y,scrollctrHR);}

charput((valueOL/10),x,(y + cntr1 - 8));
charput((valueOL%10),x+8,(y + cntr1 - 8));

charput((value/10),x,(y + cntr1 ));
charput((value%10),x+8,(y + cntr1 ));

if (cntr1 > 0){cntr1--;}
return cntr1;
}

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 = 5; // compare match register 16MHz/256/2Hz -----------------------------------> delay time (lcd flicker/brightness)
TCCR1B |= (1 << WGM12); // CTC mode, free-running, clear on match
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt


Wire.begin();
Serial.begin(9600);
delay(2000); // This delay allows the MCU to read the current date and time.
Serial.print("The current date and time is: ");
printTime();
Serial.println("Please change to newline ending the settings on the lower right of the Serial Monitor");
Serial.println("Would you like to set the date and time now? Y/N");
while (!Serial.available()) delay(10);
if (Serial.read() == 'y' || Serial.read() == 'Y')
// This set of functions allows the user to change the date and time
{
Serial.read();
setTime();
Serial.print("The current date and time is now: ");
printTime();
}
Serial.println("Thank you.");


interrupts(); // enable all interrupts

} // End main

void loop() //just sitting here
{

byte secondBK = 0;
byte minuteBK = 0;
byte hourBK = 0;

byte secondLA = 0;
byte minuteLA = 0;
byte hourLA = 0;

unsigned char scrollctrHR= 0;
unsigned char scrollctrMN = 0;
unsigned char scrollctrSE = 0;

clr();
charput(58,0,0);
charput(58,2,0);

Blit();
delay(300);

readTime();
if (second != secondBK){secondLA = secondBK; secondBK=second;scrollctrSE=8;} else {charput((second/10),3,0);charput((second%10),11,0);}
if (scrollctrSE > 0){scrollctrSE = Vscroll(second, secondLA, 3,0,scrollctrSE);}


if (minute != minuteBK ){minuteLA = minuteBK; minuteBK =minute;scrollctrMN=8;} else {charput((minute/10),19,0);charput((minute%10),27,0);}
if (scrollctrMN > 0){scrollctrMN = Vscroll(minute, minuteLA, 19,0,scrollctrMN);}


//if (hour != hourBK ){hourLA = hourBK; hourBK =hour;scrollctrHR=8;} else {charput((hour/10),x,0);charput((hour%10),x,0);}
//if (scrollctrHR > 0){scrollctrHR = Vscroll(hour, hourLA, x,0,scrollctrHR);}

Blit();
delay(300);
}
 
Doggy, we're RAMMING out of RAM :( (lol, couldn't find my RTC's at first at storage.....time is now set):
C:
Arduino: 1.6.7 (Windows 7), TD: 1.27, Board: "Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)"

Sketch uses 9,408 bytes (30%) of program storage space. Maximum is 30,720 bytes.
Global variables use 2,268 bytes (110%) of dynamic memory, leaving -220 bytes for local variables. Maximum is 2,048 bytes.
processing.app.debug.RunnerException: Not enough memory; see [URL]https://www.arduino.cc/en/Guide/Troubleshooting#size[/URL] for tips on reducing your footprint.
   at cc.arduino.Compiler.size(Compiler.java:323)
   at cc.arduino.Compiler.build(Compiler.java:157)
   at processing.app.Sketch.build(Sketch.java:1108)
   at processing.app.Sketch.build(Sketch.java:1083)
   at processing.app.Editor$BuildHandler.run(Editor.java:2019)
   at java.lang.Thread.run(Thread.java:745)
Not enough memory; see [URL]https://www.arduino.cc/en/Guide/Troubleshooting#size[/URL] for tips on reducing your footprint.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
 
Last edited:
sadly, I'm not on breadboard anymore
 
thats ok , dont need , just mistook that those pins were different. also we dont need day month year rite? will delete that to help mem, also did you say 12 hr clock or 24?


#include <Wire.h>
#include "FontMap.h"

unsigned char dataPin = 2; // ic: 14, ser_in Define which pins will be used for the Shift Register control
unsigned char latchPin = 3; // ic:12 silkscreen numbers!
unsigned char clockPin = 4;


const int DS1307 = 0x68; // Address of DS1307 see data sheets
const char* days[] =
{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const char* months[] =
{"January", "February", "March", "April", "May", "June", "July", "August","September", "October", "November", "December"};
// Initializes all values:
byte second = 0;
byte minute = 0;
byte hour = 0;



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
{
if(TIFR2) // Make sure its the timer interrupt.
{
setcolumn(displayPointer);
setdata(buffer1[displayPointer]);
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
}



byte decToBcd(byte val) {
return ((val/10*16) + (val%10));
}
byte bcdToDec(byte val) {
return ((val/16*10) + (val%16));
}


// This set of codes is allows input of data
void setTime() {

Serial.print("Please enter the current hour in 24hr format, 0-23. - ");
hour = readByte();
Serial.println(hour);
Serial.print("Please enter the current minute, 0-59. - ");
minute = readByte();
Serial.println(minute);
second = 0;
Serial.println("The data has been entered.");
// The following codes transmits the data to the RTC
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(byte(0));
Wire.endTransmission();
// Ends transmission of data
}


byte readByte() {
while (!Serial.available()) delay(10);
byte reading = 0;
byte incomingByte = Serial.read();
while (incomingByte != '\n') {
if (incomingByte >= '0' && incomingByte <= '9')
reading = reading * 10 + (incomingByte - '0');
else;
incomingByte = Serial.read();
}
Serial.flush();
return reading;
}


void printTime() {
char buffer[3];
const char* AMPM = 0;
readTime();

if (hour > 12) {
hour -= 12;
AMPM = " PM";
}
else AMPM = " AM";
Serial.print(hour);
Serial.print(":");
sprintf(buffer, "%02d", minute);
Serial.print(buffer);
Serial.println(AMPM);
}


void readTime() {
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.endTransmission();
Wire.requestFrom(DS1307, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read());

}


void setcolumn(unsigned char col){
signed char pos;
for (pos = 32;pos>-1;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 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;
}
}


unsigned char Vscroll(unsigned char value,unsigned char valueOL, signed char x,signed char y, unsigned char cntr1){ // Vscroll(hour, hourLA, x,y,scrollctrHR);}

charput((valueOL/10),x,(y + cntr1 - 8));
charput((valueOL%10),x+8,(y + cntr1 - 8));

charput((value/10),x,(y + cntr1 ));
charput((value%10),x+8,(y + cntr1 ));

if (cntr1 > 0){cntr1--;}
return cntr1;
}

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 = 5; // compare match register 16MHz/256/2Hz -----------------------------------> delay time (lcd flicker/brightness)
TCCR1B |= (1 << WGM12); // CTC mode, free-running, clear on match
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt


Wire.begin();
Serial.begin(9600);
delay(2000); // This delay allows the MCU to read the current date and time.
Serial.print("The current date and time is: ");
printTime();
Serial.println("Please change to newline ending the settings on the lower right of the Serial Monitor");
Serial.println("Would you like to set the date and time now? Y/N");
while (!Serial.available()) delay(10);
if (Serial.read() == 'y' || Serial.read() == 'Y')
// This set of functions allows the user to change the date and time
{
Serial.read();
setTime();
Serial.print("The current date and time is now: ");
printTime();
}
Serial.println("Thank you.");


interrupts(); // enable all interrupts

} // End main

void loop() //just sitting here
{

byte secondBK = 0;
byte minuteBK = 0;
byte hourBK = 0;

byte secondLA = 0;
byte minuteLA = 0;
byte hourLA = 0;

unsigned char scrollctrHR= 0;
unsigned char scrollctrMN = 0;
unsigned char scrollctrSE = 0;

clr();
charput(58,0,0);
charput(58,2,0);

Blit();
delay(300);

readTime();
if (second != secondBK){secondLA = secondBK; secondBK=second;scrollctrSE=8;} else {charput((second/10),3,0);charput((second%10),11,0);}
if (scrollctrSE > 0){scrollctrSE = Vscroll(second, secondLA, 3,0,scrollctrSE);}


if (minute != minuteBK ){minuteLA = minuteBK; minuteBK =minute;scrollctrMN=8;} else {charput((minute/10),19,0);charput((minute%10),27,0);}
if (scrollctrMN > 0){scrollctrMN = Vscroll(minute, minuteLA, 19,0,scrollctrMN);}


//if (hour != hourBK ){hourLA = hourBK; hourBK =hour;scrollctrHR=8;} else {charput((hour/10),x,0);charput((hour%10),x,0);}
//if (scrollctrHR > 0){scrollctrHR = Vscroll(hour, hourLA, x,0,scrollctrHR);}

Blit();
delay(300);
}
 
Ah, of course! 24 hrs clock preferably
96% RAM used now with that code, whined about possible stability problems....
But, it's stable, all leds lit, all the time, no flicker :/
was thinking of hooking teensy but gnd pin is not at same place as pro mini's, unless used from breadboard/similar gizmo hacks.
 
would need to compare datasheets for such anomalies in other pins, if difference is small enough we may be able to mod, not required though, we can do lots of cleanup in code to make room.


#include <Wire.h>
#include "FontMap.h"

unsigned char dataPin = 2; // ic: 14, ser_in Define which pins will be used for the Shift Register control
unsigned char latchPin = 3; // ic:12 silkscreen numbers!
unsigned char clockPin = 4;


const int DS1307 = 0x68; // Address of DS1307 see data sheets

byte second = 0;
byte minute = 0;
byte hour = 0;



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
{
if(TIFR2) // Make sure its the timer interrupt.
{
setcolumn(displayPointer);
setdata(buffer1[displayPointer]);
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
}



byte decToBcd(byte val) {
return ((val/10*16) + (val%10));
}
byte bcdToDec(byte val) {
return ((val/16*10) + (val%16));
}


// This set of codes is allows input of data
void setTime() {

Serial.print("Please enter the current hour in 24hr format, 0-23. - ");
hour = readByte();
Serial.println(hour);
Serial.print("Please enter the current minute, 0-59. - ");
minute = readByte();
Serial.println(minute);
second = 0;
Serial.println("The data has been entered.");
// The following codes transmits the data to the RTC
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(byte(0));
Wire.endTransmission();
// Ends transmission of data
}


byte readByte() {
while (!Serial.available()) delay(10);
byte reading = 0;
byte incomingByte = Serial.read();
while (incomingByte != '\n') {
if (incomingByte >= '0' && incomingByte <= '9')
reading = reading * 10 + (incomingByte - '0');
else;
incomingByte = Serial.read();
}
Serial.flush();
return reading;
}


void printTime() {
char buffer[3];
const char* AMPM = 0;
readTime();

if (hour > 12) {
hour -= 12;
AMPM = " PM";
}
else AMPM = " AM";
Serial.print(hour);
Serial.print(":");
sprintf(buffer, "%02d", minute);
Serial.print(buffer);
Serial.println(AMPM);
}


void readTime() {
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.endTransmission();
Wire.requestFrom(DS1307, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read());

}


void setcolumn(unsigned char col){
signed char pos;
for (pos = 32;pos>-1;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 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;
}
}


unsigned char Vscroll(unsigned char value,unsigned char valueOL, signed char x,signed char y, unsigned char cntr1){ // Vscroll(hour, hourLA, x,y,scrollctrHR);}

charput((valueOL/10),x,(y + cntr1 - 8));
charput((valueOL%10),x+8,(y + cntr1 - 8));

charput((value/10),x,(y + cntr1 ));
charput((value%10),x+8,(y + cntr1 ));

if (cntr1 > 0){cntr1--;}
return cntr1;
}

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 = 5; // compare match register 16MHz/256/2Hz -----------------------------------> delay time (lcd flicker/brightness)
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


clr();
charput(58,1,0);
charput(58,3,0);
charput(58,5,0);
charput(58,7,0);
charput(58,9,0);
charput(1,11,0);
charput(7,19,0);

Blit();
delay(300);

Wire.begin();
Serial.begin(9600);
delay(2000); // This delay allows the MCU to read the current date and time.
Serial.print("The current date and time is: ");
printTime();
Serial.println("Please change to newline ending the settings on the lower right of the Serial Monitor");
Serial.println("Would you like to set the date and time now? Y/N");
while (!Serial.available()) delay(10);
if (Serial.read() == 'y' || Serial.read() == 'Y')
// This set of functions allows the user to change the date and time
{
Serial.read();
setTime();
Serial.print("The current date and time is now: ");
printTime();
}
Serial.println("Thank you.");


} // End main

void loop() //just sitting here
{

byte secondBK = 0;
byte minuteBK = 0;
byte hourBK = 0;

byte secondLA = 0;
byte minuteLA = 0;
byte hourLA = 0;

unsigned char scrollctrHR= 0;
unsigned char scrollctrMN = 0;
unsigned char scrollctrSE = 0;

clr();
charput(58,0,0);
charput(58,2,0);

Blit();
delay(300);

readTime();
if (second != secondBK){secondLA = secondBK; secondBK=second;scrollctrSE=8;} else {charput((second/10),3,0);charput((second%10),11,0);}
if (scrollctrSE > 0){scrollctrSE = Vscroll(second, secondLA, 3,0,scrollctrSE);}


if (minute != minuteBK ){minuteLA = minuteBK; minuteBK =minute;scrollctrMN=8;} else {charput((minute/10),19,0);charput((minute%10),27,0);}
if (scrollctrMN > 0){scrollctrMN = Vscroll(minute, minuteLA, 19,0,scrollctrMN);}


//if (hour != hourBK ){hourLA = hourBK; hourBK =hour;scrollctrHR=8;} else {charput((hour/10),x,0);charput((hour%10),x,0);}
//if (scrollctrHR > 0){scrollctrHR = Vscroll(hour, hourLA, x,0,scrollctrHR);}

Blit();
delay(300);
}
 
At least something now appeared (compiled with teensy and bunch of errors popped so it's not plug'n play, not intended though)
IMG_1236.jpg
 
#include <Wire.h>
#include "FontMap.h"

unsigned char dataPin = 2; // ic: 14, ser_in Define which pins will be used for the Shift Register control
unsigned char latchPin = 3; // ic:12 silkscreen numbers!
unsigned char clockPin = 4;


const int DS1307 = 0x68; // Address of DS1307 see data sheets

byte second = 0;
byte minute = 0;
byte hour = 0;



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
{
if(TIFR2) // Make sure its the timer interrupt.
{
setcolumn(displayPointer);
setdata(buffer1[displayPointer]);
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
}



byte decToBcd(byte val) {
return ((val/10*16) + (val%10));
}
byte bcdToDec(byte val) {
return ((val/16*10) + (val%16));
}


// This set of codes is allows input of data
void setTime() {

Serial.print("Please enter the current hour in 24hr format, 0-23. - ");
hour = readByte();
Serial.println(hour);
Serial.print("Please enter the current minute, 0-59. - ");
minute = readByte();
Serial.println(minute);
second = 0;
Serial.println("The data has been entered.");
// The following codes transmits the data to the RTC
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(byte(0));
Wire.endTransmission();
// Ends transmission of data
}


byte readByte() {
while (!Serial.available()) delay(10);
byte reading = 0;
byte incomingByte = Serial.read();
while (incomingByte != '\n') {
if (incomingByte >= '0' && incomingByte <= '9')
reading = reading * 10 + (incomingByte - '0');
else;
incomingByte = Serial.read();
}
Serial.flush();
return reading;
}


void printTime() {
char buffer[3];
const char* AMPM = 0;
readTime();

if (hour > 12) {
hour -= 12;
AMPM = " PM";
}
else AMPM = " AM";
Serial.print(hour);
Serial.print(":");
sprintf(buffer, "%02d", minute);
Serial.print(buffer);
Serial.println(AMPM);
}


void readTime() {
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.endTransmission();
Wire.requestFrom(DS1307, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read());

}


void setcolumn(unsigned char col){
signed char pos;
for (pos = 32;pos>-1;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 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;
}
}


unsigned char Vscroll(unsigned char value,unsigned char valueOL, signed char x,signed char y, unsigned char cntr1){ // Vscroll(hour, hourLA, x,y,scrollctrHR);}

charput((valueOL/10),x,(y + cntr1 - 8));
charput((valueOL%10),x+8,(y + cntr1 - 8));

charput((value/10),x,(y + cntr1 ));
charput((value%10),x+8,(y + cntr1 ));

if (cntr1 > 0){cntr1--;}
return cntr1;
}

void setup() //setup runs once
{
signed char cntr;
unsigned char timeout = 0;
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 5; // compare match register 16MHz/256/2Hz -----------------------------------> delay time (lcd flicker/brightness)
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


clr();
charput(58,1,0);
charput(58,3,0);
charput(58,5,0);
charput(58,7,0);
charput(58,9,0);
charput(1,11,0);
charput(7,19,0);

Blit();
delay(300);

Wire.begin();
Serial.begin(9600);
delay(2000); // This delay allows the MCU to read the current date and time.
Serial.print("The current date and time is: ");
printTime();
Serial.println("Please change to newline ending the settings on the lower right of the Serial Monitor");
Serial.println("Would you like to set the date and time now? Y/N");
while (!Serial.available() & timeout < 254){ delay(20);timeout++;}
if (Serial.read() == 'y' || Serial.read() == 'Y')
// This set of functions allows the user to change the date and time
{
Serial.read();
setTime();
Serial.print("The current date and time is now: ");
printTime();
}
Serial.println("Thank you.");


} // End main

void loop() //just sitting here
{

byte secondBK = 0;
byte minuteBK = 0;
byte hourBK = 0;

byte secondLA = 0;
byte minuteLA = 0;
byte hourLA = 0;

unsigned char scrollctrHR= 0;
unsigned char scrollctrMN = 0;
unsigned char scrollctrSE = 0;

clr();
charput(58,0,0);
charput(58,2,0);

Blit();
delay(300);

readTime();
if (second != secondBK){secondLA = secondBK; secondBK=second;scrollctrSE=8;} else {charput((second/10),3,0);charput((second%10),11,0);}
if (scrollctrSE > 0){scrollctrSE = Vscroll(second, secondLA, 3,0,scrollctrSE);}


if (minute != minuteBK ){minuteLA = minuteBK; minuteBK =minute;scrollctrMN=8;} else {charput((minute/10),19,0);charput((minute%10),27,0);}
if (scrollctrMN > 0){scrollctrMN = Vscroll(minute, minuteLA, 19,0,scrollctrMN);}


//if (hour != hourBK ){hourLA = hourBK; hourBK =hour;scrollctrHR=8;} else {charput((hour/10),x,0);charput((hour%10),x,0);}
//if (scrollctrHR > 0){scrollctrHR = Vscroll(hour, hourLA, x,0,scrollctrHR);}

Blit();
delay(300);
}
 
Same screen as earlier, no change.
Errors on teensy 3.2: (not that much thankfully)
Also, if we start using teensy, it has internal RTC, saves some wiring :) Haven't touched teensy much yet, just basic testing
C:
Arduino: 1.6.7 (Windows 7), TD: 1.27, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz optimized (overclock), US English"

Build options changed, rebuilding all
sketch_jan21a:22: error: expected constructor, destructor, or type conversion before '(' token
ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
^
sketch_jan21a:22: error: expected constructor, destructor, or type conversion before '(' token
ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
^
In file included from C:\Users\Atte\AppData\Local\Temp\arduino_6d4799411362b184c1851ba8af345ff2\sketch_jan21a.ino:2:0:
C:\Users\Atte\AppData\Local\Temp\build6d4799411362b184c1851ba8af345ff2.tmp\sketch\FontMap.h:4:22: warning: 'font' defined but not used [-Wunused-variable]
static unsigned char font [1000] =  //numbers stored here
^
exit status 1
expected constructor, destructor, or type conversion before '(' token

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
 
Last edited:
it looks like it just uses interrupt differently,

as for other problem, should be getting more on display after 5-10seconds, try connecting to serial port , see if you can still program the time ....
 
Hmm, nothing is changed when using serial monitor, doesn't even read anything on serial monitor. Odd.
 
#include <Wire.h>
#include "FontMap.h"

unsigned char dataPin = 2; // ic: 14, ser_in Define which pins will be used for the Shift Register control
unsigned char latchPin = 3; // ic:12 silkscreen numbers!
unsigned char clockPin = 4;


const int DS1307 = 0x68; // Address of DS1307 see data sheets

byte second = 0;
byte minute = 0;
byte hour = 0;



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
{
if(TIFR2) // Make sure its the timer interrupt.
{
setcolumn(displayPointer);
setdata(buffer1[displayPointer]);
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
}



byte decToBcd(byte val) {
return ((val/10*16) + (val%10));
}
byte bcdToDec(byte val) {
return ((val/16*10) + (val%16));
}


// This set of codes is allows input of data
void setTime() {

Serial.print("Please enter the current hour in 24hr format, 0-23. - ");
hour = readByte();
Serial.println(hour);
Serial.print("Please enter the current minute, 0-59. - ");
minute = readByte();
Serial.println(minute);
second = 0;
Serial.println("The data has been entered.");
// The following codes transmits the data to the RTC
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(byte(0));
Wire.endTransmission();
// Ends transmission of data
}


byte readByte() {
while (!Serial.available()) delay(10);
byte reading = 0;
byte incomingByte = Serial.read();
while (incomingByte != '\n') {
if (incomingByte >= '0' && incomingByte <= '9')
reading = reading * 10 + (incomingByte - '0');
else;
incomingByte = Serial.read();
}
Serial.flush();
return reading;
}


void printTime() {
char buffer[3];
const char* AMPM = 0;
readTime();

if (hour > 12) {
hour -= 12;
AMPM = " PM";
}
else AMPM = " AM";
Serial.print(hour);
Serial.print(":");
sprintf(buffer, "%02d", minute);
Serial.print(buffer);
Serial.println(AMPM);
}


void readTime() {
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.endTransmission();
Wire.requestFrom(DS1307, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read());

}


void setcolumn(unsigned char col){
signed char pos;
for (pos = 32;pos>-1;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 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;
}
}


unsigned char Vscroll(unsigned char value,unsigned char valueOL, signed char x,signed char y, unsigned char cntr1){ // Vscroll(hour, hourLA, x,y,scrollctrHR);}

charput((valueOL/10),x,(y + cntr1 - 8));
charput((valueOL%10),x+8,(y + cntr1 - 8));

charput((value/10),x,(y + cntr1 ));
charput((value%10),x+8,(y + cntr1 ));

if (cntr1 > 0){cntr1--;}
return cntr1;
}

void setup() //setup runs once
{
signed char cntr;
unsigned char timeout = 0;
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 5; // compare match register 16MHz/256/2Hz -----------------------------------> delay time (lcd flicker/brightness)
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


clr();
charput(58,1,0);
Blit();
delay(300);

Wire.begin();

clr();
charput(58,2,0);
Blit();
Serial.begin(9600);

clr();
charput(58,3,0);
Blit();
delay(2000); // This delay allows the MCU to read the current date and time.
Serial.print("The current date and time is: ");
printTime();

clr();
charput(58,4,0);
Blit();
Serial.println("Please change to newline ending the settings on the lower right of the Serial Monitor");
Serial.println("Would you like to set the date and time now? Y/N");
while (!Serial.available() & timeout < 254){ delay(20);timeout++;

clr();
charput(58,5,0);
Blit();
}
if (Serial.read() == 'y' || Serial.read() == 'Y')
// This set of functions allows the user to change the date and time
{
Serial.read();
setTime();
Serial.print("The current date and time is now: ");
printTime();
}
Serial.println("Thank you.");


} // End main

void loop() //just sitting here
{

byte secondBK = 0;
byte minuteBK = 0;
byte hourBK = 0;

byte secondLA = 0;
byte minuteLA = 0;
byte hourLA = 0;

unsigned char scrollctrHR= 0;
unsigned char scrollctrMN = 0;
unsigned char scrollctrSE = 0;

clr();
charput(58,0,0);
charput(58,2,0);

Blit();
delay(300);

readTime();
if (second != secondBK){secondLA = secondBK; secondBK=second;scrollctrSE=8;} else {charput((second/10),3,0);charput((second%10),11,0);}
if (scrollctrSE > 0){scrollctrSE = Vscroll(second, secondLA, 3,0,scrollctrSE);}


if (minute != minuteBK ){minuteLA = minuteBK; minuteBK =minute;scrollctrMN=8;} else {charput((minute/10),19,0);charput((minute%10),27,0);}
if (scrollctrMN > 0){scrollctrMN = Vscroll(minute, minuteLA, 19,0,scrollctrMN);}


//if (hour != hourBK ){hourLA = hourBK; hourBK =hour;scrollctrHR=8;} else {charput((hour/10),x,0);charput((hour%10),x,0);}
//if (scrollctrHR > 0){scrollctrHR = Vscroll(hour, hourLA, x,0,scrollctrHR);}

Blit();
delay(300);
}
 
hmm?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top