30 return "v3.4 FRIENDLY FROG 05-01-25";
51 static uint16_t bufferA[8];
52 static uint16_t bufferB[8];
55 static uint16_t *backBuffer;
56 static uint16_t *frontBuffer;
59 static byte buttonStates[] = {0, 0, 0, 0, 0};
60 static byte debouncedButtonStates[] = {0, 0, 0, 0, 0};
61 static byte buttonDebounceCounters[] = {0, 0, 0, 0, 0};
62 static byte buttonWentDown[] = {0, 0, 0, 0, 0};
63 static byte buttonWentDownInLastLoop[] = {0, 0, 0, 0, 0};
64 static int boardRev = -1;
116 static void fastShiftOutRows(byte n)
119 for (
int i = 7; i >= 0; i--)
133 static void fastShiftOutCols(uint16_t n)
136 for (
int i = 15; i >= 0; --i)
149 static void setupInterrupt();
172 tft.print(
"Arduino LED\n\n");
180 for(
int i=0;i<4;i++){
181 uint16_t r = (*colourMap++ >> 3) & 0x1f;
183 uint16_t g = (*colourMap++ >> 2) & 0x3f;
185 uint16_t b = (*colourMap++ >> 3) & 0x1f;
194 pinMode(
CDATA, OUTPUT);
197 pinMode(
RDATA, OUTPUT);
202 digitalWrite(
RLATCH, LOW);
204 digitalWrite(
RLATCH, HIGH);
206 digitalWrite(
CLATCH, LOW);
208 digitalWrite(
CLATCH, HIGH);
212 pinMode(A0, INPUT_PULLUP);
213 pinMode(A1, INPUT_PULLUP);
214 pinMode(A2, INPUT_PULLUP);
215 pinMode(A3, INPUT_PULLUP);
216 pinMode(9, INPUT_PULLUP);
222 backBuffer = bufferA;
223 frontBuffer = bufferB;
225 memset(backBuffer, 0, 16);
226 memset(frontBuffer, 0, 16);
229 prevTxtBuffer[0] = 0;
237 static void renderText(){
238 if(strcmp(txtBuffer, prevTxtBuffer)){
239 Serial.println(txtBuffer);
240 strcpy(prevTxtBuffer, txtBuffer);
246 tft.print(txtBuffer);
264 for (
int i = 0; i < 5; i++)
266 buttonWentDownInLastLoop[i] = buttonWentDown[i];
267 buttonWentDown[i] = 0;
268 buttonStates[i] = debouncedButtonStates[i];
275 frontBuffer = backBuffer;
307 if(strlen(txtBuffer) + strlen(s) + 1 <
MAXTEXTLEN){
308 strcat(txtBuffer, s);
317 snprintf(tmp, 16,
"%d", n);
322 bool showpattern =
true;
326 for(
int i=0;i<8;i++){
333 showpattern = !showpattern;
343 return buttonStates[c - 1];
348 return buttonWentDownInLastLoop[c - 1];
363 if (x < 8 && y < 8 && x >= 0 && y >= 0)
365 uint16_t *p = backBuffer + y;
378 memset(backBuffer, 0, 16);
386 static int refrow = 0;
393 uint16_t
v = *(frontBuffer + refrow);
396 for(
int x=0;x<8;x++){
397 uint16_t q = (v >> (x*2)) & 3;
398 tft.
fillRect(16*x+2, 16*refrow+2, 12, 12, cols[q]);
408 PORTD &= ~((1 << 3) | (1 << 7));
421 fastShiftOutCols(~(frontBuffer[refrow]));
424 PORTD |= ((1 << 3) | (1 << 7));
427 refrow = (refrow + 1) % 8;
445 for (
int volatile i = 0; i < 30; i++)
447 __asm__ __volatile__(
"nop\n\t");
451 PORTD &= ~((1 << 3) | (1 << 7));
452 fastShiftOutCols(0xffff);
453 PORTD |= ((1 << 3) | (1 << 7));
466 static byte trueButtonStates[] = {0, 0, 0, 0, 0};
467 static byte button = 0;
471 if (boardRev ==
REV00)
514 bstate = bstate ? 0 : 1;
516 if (bstate != trueButtonStates[button])
518 buttonDebounceCounters[button] = 0;
520 buttonWentDown[button] = 1;
522 else if (++buttonDebounceCounters[button] == 4)
524 buttonDebounceCounters[button] = 0;
525 debouncedButtonStates[button] = bstate;
527 trueButtonStates[button] = bstate;
529 button = (button + 1) % 5;
535 static void setupInterrupt()
549 TCCR1B |= (1 << WGM12);
550 TCCR1B |= (1 << CS11) | (1 << CS10);
556 TCCR1B |= (1 << WGM12);
558 TCCR1B |= (1 << CS11);
561 TIMSK1 |= (1 << OCIE1A);
void clear()
Set all pixels in the back buffer to black.
void setRotation(uint8_t r)
Use a TFT screen display (this is the default)
int UP
the number for button S1, the "up" button
void begin(AberLEDFlags flags=AF_TFTDISPLAY, uint8_t *colourMap=NULL)
Initialises all pin modes, clears the buffers, starts the interrupt and begins to output data to the ...
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
int getButtonDown(unsigned char c)
Return nonzero if the button has been pressed since the last swap(). It's better to use the UP...
static void setRevision(int rev)
Call this to set the revision, after AberLED.begin() (which will set it to REV01 by default)...
AberLEDClass AberLED
this is the single instance of the LED class - for documentation see AberLEDClass.
void clearText()
clear the string which is written to the text area on a TFT display.
static void refresh()
Use only when interrupts are disabled - copies the front buffer to the display.
void setCursor(int16_t x, int16_t y)
The declaration for the AberLED class. Many implementation details are inside the AberLED implementat...
The class for the AberLED shield. One object of this class, called AberLED, is automatically created ...
Do not set up the interrupt. The screen will not be refreshed automatically. You will need to do by c...
void fillScreen(uint16_t color)
int getButton(unsigned char c)
Return nonzero if a given switch is pressed - switches are numbered 1 to 5, which is against my Golde...
static void panic(int n, const char *msg="PANIC")
Display a pattern of dots in binary, flashing on and off in yellow between two red lines...
#define YELLOW
the yellow colour for pixels, used in set()
#define RED
the red colour for pixels, used in set()
static const char * version()
return the version string
uint16_t * getBuffer()
Call this to write to the back buffer directly. It returns a pointer to the buffer: a set of 8 16-bit...
void setTextColor(uint16_t color)
int FIRE
the number for button S5, the "action" or "fire" button
int LEFT
the number for button S3, the "right" button
void addToText(const char *s)
Append a string to the text area on a TFT display. Does nothing if the display is not a TFT display...
void swap()
Call this code to finish drawing operations. It swaps the back and front buffer, so that the newly wr...
void setTextWrap(boolean wrap)
volatile int interruptTicks
int DOWN
the number for button S2, the "down" button
void set(int x, int y, unsigned char col)
This sets the given pixel in the back buffer to the given value. The pixel values are 0 (off)...
int getTicks()
Return the number of interrupt ticks which occurred in the last swap()-swap() cycle.
int RIGHT
the number for button S4, the "left" button