30 return "v3.3 ETERNAL EVENING 16-11-23";
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);
323 return buttonStates[c - 1];
328 return buttonWentDownInLastLoop[c - 1];
343 if (x < 8 && y < 8 && x >= 0 && y >= 0)
345 uint16_t *p = backBuffer + y;
358 memset(backBuffer, 0, 16);
366 static int refrow = 0;
373 uint16_t v = *(frontBuffer + refrow);
376 for(
int x=0;x<8;x++){
377 uint16_t q = (v >> (x*2)) & 3;
378 tft.
fillRect(16*x+2, 16*refrow+2, 12, 12, cols[q]);
388 PORTD &= ~((1 << 3) | (1 << 7));
401 fastShiftOutCols(~(frontBuffer[refrow]));
404 PORTD |= ((1 << 3) | (1 << 7));
407 refrow = (refrow + 1) % 8;
425 for (
int volatile i = 0; i < 30; i++)
427 __asm__ __volatile__(
"nop\n\t");
431 PORTD &= ~((1 << 3) | (1 << 7));
432 fastShiftOutCols(0xffff);
433 PORTD |= ((1 << 3) | (1 << 7));
446 static byte trueButtonStates[] = {0, 0, 0, 0, 0};
447 static byte button = 0;
451 if (boardRev ==
REV00)
494 bstate = bstate ? 0 : 1;
496 if (bstate != trueButtonStates[button])
498 buttonDebounceCounters[button] = 0;
500 buttonWentDown[button] = 1;
502 else if (++buttonDebounceCounters[button] == 4)
504 buttonDebounceCounters[button] = 0;
505 debouncedButtonStates[button] = bstate;
507 trueButtonStates[button] = bstate;
509 button = (button + 1) % 5;
515 static void setupInterrupt()
529 TCCR1B |= (1 << WGM12);
530 TCCR1B |= (1 << CS11) | (1 << CS10);
536 TCCR1B |= (1 << WGM12);
538 TCCR1B |= (1 << CS11);
541 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 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