Hello world! This is my first post. I'm quite new the arduino and am only playing as a hobby. I bought a 8 Character 14 Segment LED display and have had great fun with 74HC595 logic drivers and with a far old bit of wiring later I have a sketch which drives quite nicely.
This was upgraded to use interupt timers2 via the MsTimer2 library.
I even pushed the "font" array into PROGMEM.
Next step was to develop this as a library.
What I'm trying to do, and wishing Mellis would write the advanced library tutorial, is to wrap/embed the MsTimer2 library within my Library so any sketch need only have the one #include.
Is this doomed to failure? I've out of my depth with errors I'm getting back. :-[
#ifndef c8x14seg_h
#define c8x14seg_h
#define TIMER2_FREQ 3 // Timer2 interupt in milliseconds
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "MsTimer2.h"
#include "WConstants.h"
class c8x14seg {
public:
c8x14seg(int dataPin, int clockPin, int latchPin, int ledPin);
void c8display();
int bubble[8]; // "alphabet" value of character to display in corresponding bubble.
int c8x14seg_seconds;
private:
int _bub; // character of the LED and index of bubble array.
int _segPat; // hold binary for segments.
int _dataPin,_clockPin,_latchPin,_ledPin;
boolean _led; //=HIGH;
int _interupt_count;
};
#endif
/*
8x14seg.cpp - 8bubble 14 segment LED driver.
(c) Simon May Dec 2008
v0.1 19.12.2008 Simon May initial version
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "WProgram.h"
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <MsTimer2.h>
#include <c8x14seg.h>
void c8x14seg::c8x14seg(int dataPin, int clockPin, int latchPin, int ledPin) {
_dataPin=dataPin;
_clockPin=clockPin;
_latchPin=latchPin;
_ledPin=ledPin;
pinMode(_dataPin, OUTPUT);
pinMode(_clockPin, OUTPUT);
pinMode(_latchPin, OUTPUT);
if (_ledPin ) pinMode(_ledPin, OUTPUT);
digitalWrite(_clockPin,LOW);
digitalWrite(_latchPin,HIGH);
//
_led=HIGH;
c8x14seg_seconds=0;
for (_bub=0;_bub<8;_bub++) bubble[_bub]=0;
_bub=0;
//
MsTimer2::set(TIMER2_FREQ,c8display);
MsTimer2::start();
}
/* ----------
display
*/
void c8x14seg::c8display(void) {
_segPat=bubble[_bub];
digitalWrite(_latchPin,LOW);
shiftOut(_dataPin,_clockPin,MSBFIRST,(_segPat>>8));
shiftOut(_dataPin,_clockPin,MSBFIRST,_segPat);
shiftOut(_dataPin,_clockPin,MSBFIRST,(255 ^ 1<<_bub));
digitalWrite(_latchPin,HIGH);
++_bub%=8;
if ( (_interupt_count+=TIMER2_FREQ) >= 1000 ) {
c8x14seg_seconds+=1;
_interupt_count-=1000;
if ( _ledPin ) {
_led=!_led;
digitalWrite(_ledPin,_led);
}
}
}
//fin
and the errors (some of which may well be from my crudely hacked back sketch).
c8x14seg.cpp:28: error: return type specification for constructor invalid
c8x14seg.cpp: In constructor 'c8x14seg::c8x14seg(int, int, int, int)':
c8x14seg.cpp:45: error: argument of type 'void (c8x14seg::)()' does not match 'void (*)()'
hardware\libraries\c8x14seg/c8x14seg.h:7:22: error: MsTimer2.h: No such file or directory
In file included from C:\Documents and Settings\Simon\My Documents\Arduino\arduino-0012\hardware\cores\arduino/WProgram.h:4,
In function 'void loop()':
In function 'void show(char*, int, int)':
In function 'void flip(int)':
I suspect the killer line is MsTimer2::set(TIMER2_FREQ,c8display);
and that I may need to cast this somehow?? :-/