diff --git a/library/QuarterK.cpp b/library/QuarterK.cpp index 40260c0..10dfb95 100644 --- a/library/QuarterK.cpp +++ b/library/QuarterK.cpp @@ -7,6 +7,7 @@ * The class is also autoinstantiated. * v1.3 Mats Engstrom - Added IsSet(). * v1.4 Mats Engstrom - Support for Arduino Mega 1280 (bitbang SPI) + * v1.5 Mats Engstrom - Fixed bug in tick handling. Support for yPos in DrawText() * * This software is licensed under the Creative Commons Attribution- * ShareAlike 3.0 Unported License. @@ -25,6 +26,10 @@ byte _framebuffer[32]; // Private framebuffer for screen refresh only volatile unsigned int tick; +unsigned int QuarterK::GetTick() { + return tick; +} + // // Bit-banged SPI function used by Mega Arduinos @@ -52,8 +57,8 @@ volatile unsigned int tick; ISR(TIMER1_COMPA_vect) { static byte nr=0; byte offset; - - tick++; + + tick++; offset=((nr+1)&0x07)*2; #if defined(__AVR_ATmega1280__) @@ -755,6 +760,7 @@ boolean QuarterK::DrawText(char *msg, uint8_t *pFont, int shift, byte xPos, byte bitmap=pgm_read_byte_near(p++); if ((x>=0) && (x<16)) { y=min(7, charHeight-1); + y+=yPos; if (bitmap&0x80) qk.Plot(x,y); y--; if (charHeight==1) continue; @@ -785,6 +791,7 @@ boolean QuarterK::DrawText(char *msg, uint8_t *pFont, int shift, byte xPos, byte for (column=0; column=0) && (x<16)) { if (bitmap&0x80) qk.Plot(x,y); @@ -825,8 +832,9 @@ boolean QuarterK::DrawText(char *msg, uint8_t *pFont, int shift, byte xPos, byte // // void QuarterK::Delay(unsigned int ms) { + unsigned int oldtick; while (ms-->0) { - unsigned int oldtick=tick; + oldtick=tick; while(tick==oldtick); }; } diff --git a/library/QuarterK.h b/library/QuarterK.h index 6c7cdc7..715923c 100644 --- a/library/QuarterK.h +++ b/library/QuarterK.h @@ -7,6 +7,7 @@ * The class is also autoinstantiated. * v1.3 Mats Engstrom - Added IsSet(). * v1.4 Mats Engstrom - Support for Arduino Mega 1280 (bitbang SPI) + * v1.5 Mats Engstrom - Fixed bug in tick handling. Support for yPos in DrawText() * * This software is licensed under the Creative Commons Attribution- * ShareAlike 3.0 Unported License. @@ -124,12 +125,16 @@ extern byte framebuffer[32]; // +extern volatile unsigned int tick; class QuarterK { public: QuarterK(void); + + unsigned int GetTick(); + void RefreshRow(); // Turn off (Clear) or on (Fill) all pixels on the display @@ -170,7 +175,7 @@ class QuarterK { // Draws a string of characters. The *pFont a pointer to a font generated by // F. Maximilian Thiele's FontGenerator. The text is offsetted by the number of pixels - // defined by shift. Currently the xPos and yPos is not implemented in the code. + // defined by shift. Currently xPos is not implemented in the code. boolean DrawText(char *msg, uint8_t *pFont, int shift, byte xPos=0, byte yPos=0); // Get the state of the fire-button on the game controller. Returns