Understanding the language, error messages, etc.
by Duhjoker » Sat Oct 08, 2016 8:07 am
OK so today I went ahead and pre-defined 16 colors just to make a quick start, I also tried to add the drawPixel stuff from the cpp to the h file but its giving me the error initializer specified for non-virtual and im having sketch errors. I now have very lil idea how to use the library now and I think I have done a couple things wrong.
errors
- Code: Select all
Arduino: 1.6.11 (Windows 7), TD: 1.30-beta3, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz optimize speed (overclock), US English"
In file included from C:\Users\duhjoker\Documents\Arduino\BITMAP\BITMAP.ino:19:0:
C:\Users\duhjoker\Documents\Arduino\libraries\mylcd/DisplayRGB.h:131:3: warning: non-static const member 'const int16_t Display::WIDTH' in class without a constructor [-Wuninitialized]
WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes
^
C:\Users\duhjoker\Documents\Arduino\libraries\mylcd/DisplayRGB.h:131:10: warning: non-static const member 'const int16_t Display::HEIGHT' in class without a constructor [-Wuninitialized]
WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes
^
BITMAP:40: error: 'display' does not name a type
display.DisplayRGBC(cs,wr,rs);
^
BITMAP: In function 'void setup()':
BITMAP:69: error: 'display' was not declared in this scope
display.begin();
^
BITMAP: In function 'void loop()':
BITMAP:81: error: 'display' was not declared in this scope
display.drawBitmap(70, 70, green_square, 16, 16, 0x07E0);
^
'display' does not name a type
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
sketch
- Code: Select all
//#include "Adafruit_GFX.h"
#include "DisplayRGB.h"
#include <SPI.h>
// pin definition for the UNO
#define cs 11
#define wr 10
#define rs 12
//#define le 13
//#define D0 9
//#define D1 8
//#define D2 7
//#define D3 6
//#define D4 5
//#define D5 4
//#define D6 3
//#define D7 2
//DisplayRGB TFTscreen(cs,wr,rs,le);
display.DisplayRGBC(cs,wr,rs);
// position of the line on screen
int xPos = 0;
const byte green_square[] PROGMEM = {
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,};
// const byte *bitmap[] = {green_square};
void setup(){
// initialize the serial port
//TFTscreen.setdatapin(D0,D1,D2,D3,D4,D5,D6,D7);
display.begin();
// initialize the display
display.begin();
// clear the screen with a pretty color
//TFTscreen.background(250,16,200);
}
void loop(){
display.drawBitmap(70, 70, green_square, 16, 16, 0x07E0);
}
.h
- Code: Select all
#ifndef DisplayRGB_H
#define DisplayRGB_H
#if ARDUINO >= 100
#include "Arduino.h"
#include "Print.h"
#else
#include "WProgram.h"
#endif
//#include "utility/Adafruit_GFX.h"
#include <SPI.h>
#include <avr/pgmspace.h>
#include "gfxfont.h"
#include "glcdfont.c"
#define LCDWIDTH 220
#define LCDHEIGHT 176
// 16 PREDEFINED COLORS
#define BLACK 0x0000
#define WHITE 0xFFFF
#define DARKGRAY 0xAD55
#define GRAY 0x8410
#define BLUE 0x001F
#define DARKBLUE 0x0011
#define TURQUOISE 0x471A
#define GREEN 0x0400
#define FORESTGREEN 0x2444
#define YELLOW 0xFFE0
#define ORANGE 0xFD20
#define PINK 0xFE19
#define RED 0xF800
#define PURPLE 0x8010
#define VIOLET 0xEC1D
#define BROWN 0xA145
#define BEIGE 0xF7BB
typedef uint16_t color;
class Display : public Print
{
public:
void Display1(int16_t w, int16_t h);// Constructor
void DisplayRGBA(uint8_t cs,uint8_t wr ,uint8_t rs , uint8_t rest ,uint8_t pmw );
void DisplayRGBB(uint8_t cs,uint8_t wr ,uint8_t rs , uint8_t rest );
void DisplayRGBC(uint8_t cs,uint8_t wr ,uint8_t rs );
//LCD_2000_7775(){};
void write_spi(const uint8_t data);
void drawPixel(int16_t x, int16_t y, uint16_t color); //gfx
void setdatapin(uint8_t b0,uint8_t b1, uint8_t b2 , uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6, uint8_t b7);
void setbacklight(uint8_t pmw);
void begin();
/////from gfx
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
void fillScreen(uint16_t color);
void invertDisplay(boolean i);
void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color);
void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color);
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
// from gamebuino display.h
//void drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap);
//void drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h, const uint8_t *bitmap);
//void drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint8_t rotation, uint8_t flip);
//void drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h, const uint8_t *bitmap, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh);
/////from gfx
void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg);
void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg);
boolean getBitmapPixel(const uint8_t* bitmap, uint8_t x, uint8_t y);
//DRAW X-BITMAP
void drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
/////from display.h summoner123
void drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet);
void drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh);
/////from gfx
void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
void setCursor(int16_t x, int16_t y);
void setTextColor(uint16_t c);
void setTextColor(uint16_t c, uint16_t bg);
void setTextSize(uint8_t s);
void setTextWrap(boolean w);
void setRotation(uint8_t r);
void cp437(boolean x = true);
void setFont(const GFXfont *f = NULL);
void getTextBounds(char *string, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
void getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
////from gfx
#if ARDUINO >= 100
virtual size_t write(uint8_t);
#else
virtual void write(uint8_t);
#endif
int16_t height(void) const;
int16_t width(void) const;
uint8_t getRotation(void) const;
// get current cursor position (get rotation safe maximum values, using: width() for x, height() for y)
int16_t getCursorX(void) const;
int16_t getCursorY(void) const;
protected:
const int16_t
WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes
int16_t
_width, _height, // Display w/h as modified by current rotation
cursor_x, cursor_y;
uint16_t
textcolor, textbgcolor;
uint8_t
textsize,
rotation;
boolean
wrap, // If set, 'wrap' text at right edge of display
_cp437; // If set, use correct CP437 charset (default is off)
GFXfont
*gfxFont;
boolean persistence; //disable clean() at each frame if true
//boolean textWrap; // If set, 'wrap' text at right edge of
uint8_t fontSize;
int8_t cursorX, cursorY;
byte contrast;
byte frameCount;
typedef struct { //line 171 "Public Variables - ADD by Summoner123
int x; //X coordinate - ADD by Summoner123
int y; //Y coordinate - ADD by Summoner123
const byte *spritecol; //Sprite of object - ADD by Summoner123
}object;
object solid[60]; // Matriz were saved a Sprite, X and Y cordinates of all tiles on the screen - ADD by Summoner123
byte numcolision = 0; //count of solid objects indacat how many tiles drawed on the screen - ADD by Summoner123
bool flagcollision = true;
//}; //
//function
private:
void set_window(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2);
void write_wr_reg(uint16_t data);
void write_wr_data(uint16_t data);
void write_cmd(uint16_t cmd ,uint16_t data);
#if 0 //defined(ARDUINO_ARCH_SAM)
void write_delay();
#else
#define write_delay()
#endif
//value
//private:
#if defined(ARDUINO_ARCH_SAM)
uint32_t _cs;
uint32_t _pmw;
uint32_t _wr;
uint32_t _rs;
uint32_t _rest;
volatile uint32_t *csport;
volatile uint32_t *pmwport;
volatile uint32_t *wrport;
volatile uint32_t *rsport;
volatile uint32_t *restport;
uint32_t cspinmask;
uint32_t pmwpinmask;
uint32_t wrpinmask;
uint32_t rspinmask;
uint32_t restpinmask;
volatile uint32_t data[8];
volatile uint32_t datapinmask[8];
volatile uint32_t* dataport[8];
#else
uint8_t _cs;
uint8_t _pmw;
uint8_t _wr;
uint8_t _rs;
uint8_t _rest;
volatile uint8_t *csport;
volatile uint8_t *pmwport;
volatile uint8_t *wrport;
volatile uint8_t *rsport;
volatile uint8_t *restport;
uint8_t cspinmask;
uint8_t pmwpinmask;
uint8_t wrpinmask;
uint8_t rspinmask;
uint8_t restpinmask;
volatile uint8_t data[8];
volatile uint8_t datapinmask[8];
volatile uint8_t* dataport[8];
#endif
};
void Display::drawPixel(int16_t x, int16_t y, uint16_t color)
{
set_window(x, y, x, y);
//this->write_wr_reg(0x0022);
//this->write_wr_data(color);
this->write_cmd(0x22, color);
};
uint16_t RGB(uint16_t r,uint16_t g , uint16_t b);
#endif
I did read the arduino guide but im not getting something, I did see that the constructor did have to have the same name as the class so that was easy to fix.
Edit saturday 3:00:: could the bitmap images that are stored in Progmem be stored on the sdCard? Like as a library that could be accessed by the sketch upon initialization.
Edit Saturday 18:00:: fixed the drawPixel problem in the DisplayRGB.h. For some reason one of the files had a =0; or something like that and after doing some looking figured out it wasn't needed. I have both the function and the definition now included with in the same file and it's not giving me those errors now.
You said in a previous post it might be easier to add the color functions straight to the Gamebuino but I could in fact do that am I to assume that SPI uses the same pin definitions like CLK DIN DC CS and RST.
edit sunday 01:30:: I edited the sketch anf .h to include my latest changes. I keep getting display not declared and I cant figure that part out
-
Duhjoker
-
- Posts: 446
- Joined: Sat Jul 02, 2016 4:57 am
- Location: Where Palm trees grow
by Duhjoker » Wed Oct 12, 2016 6:43 am
I couldn't add any more code to the last post but I think I might have a finished library. I haven't tested it yet but ive been busy all day. After looking at the source code for the buttons I saw that the pull up command was already included in the definition so all I had to do was add the extra buttons to the settings file. Im not sure what to do about the backlight source since it uses the pcd8544 stuff, prolly just set that in sketch since the function is already included in the display files void list. Niether the lcd or the gfx had the getPixel commands so I added the one from gamebuino. should it have a color argument?
I also changed the spi parts in my display file to match the gamebuinos. There are a few commands that have the pcd8544 stuff I know that it has something to do with the 5110 nokia screen but my lcd doesn't use any of that so what do I do?
Any way im including the library.
oh could someone please look at these drawbitmap commands? im having trouble with the color arguments......
- Code: Select all
void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg);
void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg);
boolean getBitmapPixel(const uint8_t* bitmap, uint8_t x, uint8_t y);
uint16_t RGB(uint16_t r,uint16_t g , uint16_t b);
heres the definitions
- Code: Select all
// Draw a 1-bit image (bitmap) at the specified (x,y) position from the
// provided bitmap buffer (must be PROGMEM memory) using the specified
// foreground color (unset bits are transparent).
void Display::drawBitmap(int16_t x, int16_t y,
const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) {
int16_t i, j, byteWidth = (w + 7) / 8;
uint8_t byte;
for (j = 0; j<h; j++) {
for (i = 0; i<w; i++) {
if (i & 7) byte <<= 1;
else byte = pgm_read_byte(bitmap + j * byteWidth + i / 8);
if (byte & 0x80) drawPixel(x + i, y + j, color);
}
}
}
// Draw a 1-bit image (bitmap) at the specified (x,y) position from the
// provided bitmap buffer (must be PROGMEM memory) using the specified
// foreground (for set bits) and background (for clear bits) colors.
void Display::drawBitmap(int16_t x, int16_t y,
const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg) {
int16_t i, j, byteWidth = (w + 7) / 8;
uint8_t byte;
for (j = 0; j<h; j++) {
for (i = 0; i<w; i++) {
if (i & 7) byte <<= 1;
else byte = pgm_read_byte(bitmap + j * byteWidth + i / 8);
if (byte & 0x80) drawPixel(x + i, y + j, color);
else drawPixel(x + i, y + j, bg);
}
}
}
// drawBitmap() variant for RAM-resident (not PROGMEM) bitmaps.
void Display::drawBitmap(int16_t x, int16_t y,
uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) {
int16_t i, j, byteWidth = (w + 7) / 8;
uint8_t byte;
for (j = 0; j<h; j++) {
for (i = 0; i<w; i++) {
if (i & 7) byte <<= 1;
else byte = bitmap[j * byteWidth + i / 8];
if (byte & 0x80) drawPixel(x + i, y + j, color);
}
}
}
// drawBitmap() variant w/background for RAM-resident (not PROGMEM) bitmaps.
void Display::drawBitmap(int16_t x, int16_t y,
uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg) {
int16_t i, j, byteWidth = (w + 7) / 8;
uint8_t byte;
for (j = 0; j<h; j++) {
for (i = 0; i<w; i++) {
if (i & 7) byte <<= 1;
else byte = bitmap[j * byteWidth + i / 8];
if (byte & 0x80) drawPixel(x + i, y + j, color);
else drawPixel(x + i, y + j, bg);
}
}
}
uint16_t RGB(uint16_t r,uint16_t g , uint16_t b)
{
uint16_t rgb = 0;
r *= 31;
r /= 255;
g *= 63;
g /= 255;
b *= 31;
b /= 255;
rgb |= (r<<11);
rgb |= (g<<6);
rgb |= b;
return rgb;
}
ive tried the word color the color name and the hex included in the define but keep getting errors and I cant figure it out which is hampering my ability to debug it by compiling my code. Ive been trying to compile that in its own library for weeks.
Last edited by
Duhjoker on Sat Oct 29, 2016 9:36 am, edited 1 time in total.
-
Duhjoker
-
- Posts: 446
- Joined: Sat Jul 02, 2016 4:57 am
- Location: Where Palm trees grow
by naed » Thu Oct 13, 2016 12:21 am
did you try getting the Nokia 5110 display working on your teensy? If you did what were your results like?
-
naed
-
- Posts: 140
- Joined: Tue May 31, 2016 3:18 pm
by Duhjoker » Thu Oct 13, 2016 4:00 am
No im still trying to get the LCD_2000_7775 going. I took Rodots advice today and just added the color bits and functions to the OG gamebuino display file. nnow its giving me trouble about the draw pixel command. I definitely need it for the drawbit map functions and a few others. I think I just need to change some syntax but I don't see why the library wouldnt work with any spi screen as long as you have the progmem space.
heres the updated display file. I removed the non color commands and replaced them. at some point ill re-add the OG functions and defintions commented out so the source has both and you can just switch back and fourth using the comments.
here are my errors
- Code: Select all
Arduino: 1.6.11 (Windows 7), TD: 1.30-beta3, Board: "Gamebuino"
In file included from C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinoduhjoker/Gamebuino.h:28:0,
from C:\Users\duhjoker\Desktop\TEST\TEST.ino:2:
C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinoduhjoker/Display.h: In member function 'void Display::drawPixel(int16_t, int16_t, uint16_t)':
C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinoduhjoker/Display.h:247:35: error: '_width' was not declared in this scope
if ((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return;
^
C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinoduhjoker/Display.h:247:52: error: '_height' was not declared in this scope
if ((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return;
^
C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinoduhjoker/Display.h:250:11: error: 'rotation' was not declared in this scope
switch (rotation) {
^
Multiple libraries were found for "Gamebuino.h"
Used: C:\Users\duhjoker\Documents\Arduino\libraries\Gamebuinoduhjoker
Not used: C:\Users\duhjoker\Documents\Arduino\libraries\LCD_2000_7775_TEENSY2
exit status 1
Error compiling for board Gamebuino.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
here is the new h file
- Code: Select all
/*
* (C) Copyright 2014 Aurélien Rodot. All rights reserved.
*
* This file is part of the Gamebuino Library (http://gamebuino.com)
*
* The Gamebuino 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>
*
* Parts of the graphical library come from the great library provided by Adafruit
* for their Nokia 5110 module which can be found here :
* https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library
* Here is their license :
*
* This is the core graphics library for all our displays, providing a common
* set of graphics primitives (points, lines, circles, etc.). It needs to be
* paired with a hardware-specific library for each display device we carry
* (to handle the lower-level functions).
* Adafruit invests time and resources providing this open source code, please
* support Adafruit & open-source hardware by purchasing products from Adafruit!
* Copyright (c) 2013 Adafruit Industries. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* This is a library for our Monochrome Nokia 5110 LCD Displays
* Pick one up today in the Adafruit shop!
* ------> http://www.adafruit.com/products/338
* These displays use SPI to communicate, 4 or 5 pins are required to
* interface
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
* Written by Limor Fried/Ladyada for Adafruit Industries.
* BSD license, check license.txt for more information
* All text above, and the splash screen below must be included in any redistribution
*/
#ifndef DISPLAY_H
#define DISPLAY_H
#include <Arduino.h>
#include <avr/pgmspace.h>
#include <SPI.h>
#include "settings.c"
//colors
//#define WHITE 0
//#define BLACK 1
//#define INVERT 2
//#define GRAY 3
//for extended bitmap function :
#define NOROT 0
#define ROTCCW 1
#define ROT180 2
#define ROTCW 3
#define NOFLIP 0
#define FLIPH 1
#define FLIPV 2
#define FLIPVH 3
#if (DISPLAY_ROT == NO_ROT)||(DISPLAY_ROT == ROT180) //landscape mode
#define LCDWIDTH 220
#define LCDHEIGHT 176
#else //portrait mode
#define LCDWIDTH 176
#define LCDHEIGHT 220
#endif
#define LCDHEIGHT_NOROT 176
#define LCDWIDTH_NOROT 220
#define swap(a, b) { int8_t t = a; a = b; b = t; }
#define PCD8544_POWERDOWN 0x04
#define PCD8544_ENTRYMODE 0x02
#define PCD8544_EXTENDEDINSTRUCTION 0x01
#define PCD8544_DISPLAYBLANK 0x0
#define PCD8544_DISPLAYNORMAL 0x4
#define PCD8544_DISPLAYALLON 0x1
#define PCD8544_DISPLAYINVERTED 0x5
// H = 0
#define PCD8544_FUNCTIONSET 0x20
#define PCD8544_DISPLAYCONTROL 0x08
#define PCD8544_SETYADDR 0x40
#define PCD8544_SETXADDR 0x80
#define PCD8544_SETXADDR 0x80
// H = 1
#define PCD8544_SETTEMP 0x04
#define PCD8544_SETBIAS 0x10
#define PCD8544_SETVOP 0x80
extern uint8_t _displayBuffer[];
typedef uint16_t color;
class Display : public Print {
public:
void begin(int8_t SCLK, int8_t DIN, int8_t DC, int8_t CS, int8_t RST);
void command(uint8_t c);
void data(uint8_t c);
uint8_t* getBuffer();
void setContrast(uint8_t val);
void clear(void);
void update();
void setColor(int8_t c);
void setColor(int8_t c, int8_t bg);
inline void drawPixel(int16_t x, int16_t y, uint16_t color);
//inline uint8_t getPixel(int8_t x, int8_t y);
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
void fillScreen(uint16_t color);
void invertDisplay(boolean i);
void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color);
void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color);
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg);
void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg);
boolean getBitmapPixel(const uint8_t* bitmap, uint8_t x, uint8_t y);
void drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet);
void drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet,uint8_t dx,uint8_t dy,uint8_t dw,uint8_t dh);
void setFont(const uint8_t* f); uint8_t fontWidth, fontHeight;
void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
virtual size_t write(uint8_t);
boolean persistence; //disable clean() at each frame if true
boolean textWrap; // If set, 'wrap' text at right edge of
uint8_t fontSize;
int8_t cursorX, cursorY;
byte contrast;
byte frameCount;
typedef struct{ //line 171 "Public Variables - ADD by Summoner123
int x; //X coordinate - ADD by Summoner123
int y; //Y coordinate - ADD by Summoner123
const byte *spritecol; //Sprite of object - ADD by Summoner123
}object;
object solid[60]; // Matriz were saved a Sprite, X and Y cordinates of all tiles on the screen - ADD by Summoner123
byte numcolision = 0; //count of solid objects indacat how many tiles drawed on the screen - ADD by Summoner123
bool flagcollision = true;
private:
int8_t sclk, din, dc, cs, rst;
volatile uint8_t *mosiport, *clkport, *csport, *dcport;
uint8_t mosipinmask, clkpinmask, cspinmask, dcpinmask;
uint8_t *font;
uint8_t color, bgcolor;
};
inline uint8_t* Display::getBuffer(){
return _displayBuffer;
}
/*inline void Display::drawPixel(int8_t x, int8_t y) {
if ((x < 0) || (x >= LCDWIDTH) || (y < 0) || (y >= LCDHEIGHT))
return;
byte c = color;
if(color == INVERT){
c = !getPixel(x, y);
} else if(color == GRAY){
if(((frameCount & 0x01) ^ ((x & 0x01) ^ (y & 0x01)) == 0)){ //alternative checkers pattern
c = WHITE;
} else {
c= BLACK;
}
}
if(c == WHITE){ //white
#if DISPLAY_ROT == NOROT
_displayBuffer[x + (y / 8) * LCDWIDTH_NOROT] &= ~_BV(y % 8);
#elif DISPLAY_ROT == ROTCCW
_displayBuffer[LCDHEIGHT - y - 1 + (x / 8) * LCDWIDTH_NOROT] &= ~_BV(x % 8);
#elif DISPLAY_ROT == ROT180
_displayBuffer[LCDWIDTH - x - 1 + ((LCDHEIGHT - y - 1) / 8) * LCDWIDTH_NOROT] &= ~_BV((LCDHEIGHT - y - 1) % 8);
#elif DISPLAY_ROT == ROTCW
_displayBuffer[y + ((LCDWIDTH - x - 1) / 8) * LCDWIDTH_NOROT] &= ~_BV((LCDWIDTH - x - 1) % 8);
#endif
return;
}
else { //black
#if DISPLAY_ROT == NOROT
_displayBuffer[x + (y / 8) * LCDWIDTH_NOROT] |= _BV(y % 8);
#elif DISPLAY_ROT == ROTCCW
_displayBuffer[LCDHEIGHT - y - 1 + (x / 8) * LCDWIDTH_NOROT] |= _BV(x % 8);
#elif DISPLAY_ROT == ROT180
_displayBuffer[LCDWIDTH - x - 1 + ((LCDHEIGHT - y - 1) / 8) * LCDWIDTH_NOROT] |= _BV((LCDHEIGHT - y - 1) % 8);
#elif DISPLAY_ROT == ROTCW
_displayBuffer[y + ((LCDWIDTH - x - 1) / 8) * LCDWIDTH_NOROT] |= _BV((LCDWIDTH - x -1) % 8);
#endif
return;
}
}
inline uint8_t Display::getPixel(int8_t x, int8_t y) {
if ((x < 0) || (x >= LCDWIDTH) || (y < 0) || (y >= LCDHEIGHT))
return 0;
return (_displayBuffer[x + (y / 8) * LCDWIDTH] >> (y % 8)) & 0x1;
}*/
void Display::drawPixel(int16_t x, int16_t y, uint16_t color) {
if (_displayBuffer) {
if ((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return;
int16_t t;
switch (rotation) {
case 1:
t = x;
x = LCDWIDTH - 1 - y;
y = t;
break;
case 2:
x = LCDWIDTH - 1 - x;
y = LCDHEIGHT - 1 - y;
break;
case 3:
t = x;
x = y;
y = LCDHEIGHT - 1 - t;
break;
}
_displayBuffer[x + y * LCDWIDTH] = color;
}
}
uint16_t RGB(uint16_t r, uint16_t g, uint16_t b);
#endif /* DISPLAY_H */
heres the cpp
- Code: Select all
/*
* (C) Copyright 2014 Aurélien Rodot. All rights reserved.
*
* This file is part of the Gamebuino Library (http://gamebuino.com)
*
* The Gamebuino 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>
*
* Parts of the graphical library come from the great library provided by Adafruit
* for their Nokia 5110 module which can be found here :
* https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library
* Here is their license :
*
* This is the core graphics library for all our displays, providing a common
* set of graphics primitives (points, lines, circles, etc.). It needs to be
* paired with a hardware-specific library for each display device we carry
* (to handle the lower-level functions).
* Adafruit invests time and resources providing this open source code, please
* support Adafruit & open-source hardware by purchasing products from Adafruit!
* Copyright (c) 2013 Adafruit Industries. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* This is a library for our Monochrome Nokia 5110 LCD Displays
* Pick one up today in the Adafruit shop!
* ------> http://www.adafruit.com/products/338
* These displays use SPI to communicate, 4 or 5 pins are required to
* interface
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
* Written by Limor Fried/Ladyada for Adafruit Industries.
* BSD license, check license.txt for more information
* All text above, and the splash screen below must be included in any redistribution
*/
#include "Display.h"
// a 3x5 font table
extern const uint8_t font3x5[] PROGMEM;
// the memory buffer for the LCD
uint8_t _displayBuffer[512];
//the original display buffer containing the splash screen by Adafruit
//uint8_t pcd8544_buffer[LCDWIDTH * LCDHEIGHT / 8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFF, 0xFC, 0xE0,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8,0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 0xC0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x7F,0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF, 0xFF,0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x87, 0x8F, 0x9F, 0x9F, 0xFF, 0xFF, 0xFF,0xC1, 0xC0, 0xE0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC, 0xFC, 0xFE, 0xFE, 0xFE,0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x80, 0xC0, 0xE0, 0xF1, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x0F, 0x0F, 0x87,0xE7, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0x3F, 0xF9, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xFD, 0xFF,0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,x00, 0x00, 0x00, 0xF0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,0x7E, 0x3F, 0x3F, 0x0F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xE0, 0xF1, 0xFF, 0xFF, 0xFF, 0xFF,0xFF, 0xFC, 0xF0, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01,0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x1F, 0x3F, 0x7F, 0x7F,0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x1F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
void Display::begin(int8_t SCLK, int8_t DIN, int8_t DC, int8_t CS, int8_t RST) {
din = DIN;
sclk = SCLK;
dc = DC;
rst = RST;
cs = CS;
//cursorY = cursorX = 0;
fontSize = 1;
color = BLACK;
bgcolor = WHITE;
textWrap = true;
setFont(font3x5);
//persistence = false;
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV8); //can be set to 4 but some random pixels will start to appear on some displays
SPI.setDataMode(SPI_MODE3);
// set pin directions
pinMode(din, OUTPUT);
pinMode(sclk, OUTPUT);
pinMode(dc, OUTPUT);
if (rst > 0)
pinMode(rst, OUTPUT);
if (cs > 0)
pinMode(cs, OUTPUT);
// toggle RST low to reset
if (rst > 0) {
digitalWrite(rst, LOW);
delay(10);
digitalWrite(rst, HIGH);
}
clkport = portOutputRegister(digitalPinToPort(sclk));
clkpinmask = digitalPinToBitMask(sclk);
mosiport = portOutputRegister(digitalPinToPort(din));
mosipinmask = digitalPinToBitMask(din);
csport = portOutputRegister(digitalPinToPort(cs));
cspinmask = digitalPinToBitMask(cs);
dcport = portOutputRegister(digitalPinToPort(dc));
dcpinmask = digitalPinToBitMask(dc);
// get into the EXTENDED mode!
command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION);
// LCD bias select (4 is optimal?)
command(PCD8544_SETBIAS | 0x4);
// set VOP
if (contrast > 0x7f)
contrast = 0x7f;
command(PCD8544_SETVOP | contrast); // Experimentally determined
// normal mode
command(PCD8544_FUNCTIONSET);
// Set display to Normal
command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);
// initial display line
// set page address
// set column address
// write display data
update();
}
void Display::command(uint8_t c) {
noInterrupts();
digitalWrite(dc, LOW);
if (cs > 0)
digitalWrite(cs, LOW);
SPI.transfer((char) c);
if (cs > 0)
digitalWrite(cs, HIGH);
interrupts();
}
void Display::data(uint8_t c) {
noInterrupts();
digitalWrite(dc, HIGH);
if (cs > 0)
digitalWrite(cs, LOW);
SPI.transfer((char) c);
if (cs > 0)
digitalWrite(cs, HIGH);
interrupts();
}
void Display::setContrast(uint8_t val) {
contrast = constrain(val, 30, 80);
/*if (contrast > 0x7f) {
contrast = 0x7f;
}*/
command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION);
command(PCD8544_SETVOP | contrast);
command(PCD8544_FUNCTIONSET);
}
void Display::clear(void) {
memset(_displayBuffer, 0, LCDWIDTH * LCDHEIGHT / 8);
cursorY = cursorX = 0;
}
void Display::fillScreen(uint8_t color) {
memset(_displayBuffer, 0xFFFF, LCDWIDTH * LCDHEIGHT / 8);
}
void Display::update(void) {
frameCount ++;
uint8_t col, maxcol, p;
for (p = 0; p < 6; p++) {
command(PCD8544_SETYADDR | p);
// start at the beginning of the row
col = 0;
maxcol = LCDWIDTH_NOROT - 1;
command(PCD8544_SETXADDR | col);
digitalWrite(dc, HIGH);
if (cs > 0)
digitalWrite(cs, LOW);
for (; col <= maxcol; col++) {
SPI.transfer(_displayBuffer[(LCDWIDTH_NOROT * p) + col]);
}
if (cs > 0)
digitalWrite(cs, HIGH);
}
command(PCD8544_SETYADDR); // no idea why this is necessary but it is to finish the last byte?
}
//void Display::setColor(int8_t c){
// color = c;
// bgcolor = c;
//}
//void Display::setColor(int8_t c, int8_t bg){
// color = c;
// bgcolor = bg;
//}
void Display::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
uint16_t color) {
int16_t steep = abs(y1 - y0) > abs(x1 - x0);
if (steep) {
_swap_int16_t(x0, y0);
_swap_int16_t(x1, y1);
}
if (x0 > x1) {
_swap_int16_t(x0, x1);
_swap_int16_t(y0, y1);
}
int16_t dx, dy;
dx = x1 - x0;
dy = abs(y1 - y0);
int16_t err = dx / 2;
int16_t ystep;
if (y0 < y1) {
ystep = 1;
}
else {
ystep = -1;
}
for (; x0 <= x1; x0++) {
if (steep) {
drawPixel(y0, x0, color);
}
else {
drawPixel(x0, y0, color);
}
err -= dy;
if (err < 0) {
y0 += ystep;
err += dx;
}
}
}
void Display::drawFastVLine(int16_t x, int16_t y,
int16_t h, uint16_t color) {
// Update in subclasses if desired!
drawLine(x, y, x, y + h - 1, color);
}
void Display::drawFastHLine(int16_t x, int16_t y,
int16_t w, uint16_t color) {
// Update in subclasses if desired!
drawLine(x, y, x + w - 1, y, color);
}
void Display::drawRect(int16_t x, int16_t y, int16_t w, int16_t h,
uint16_t color) {
drawFastHLine(x, y, w, color);
drawFastHLine(x, y + h - 1, w, color);
drawFastVLine(x, y, h, color);
drawFastVLine(x + w - 1, y, h, color);
}
void Display::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
uint16_t color) {
// Update in subclasses if desired!
for (int16_t i = x; i<x + w; i++) {
drawFastVLine(i, y, h, color);
}
}
void Display::fillScreen(uint16_t color) {
fillRect(0, 0, _width, _height, color);
}
void Display::drawCircle(int16_t x0, int16_t y0, int16_t r,
uint16_t color) {
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
drawPixel(x0, y0 + r, color);
drawPixel(x0, y0 - r, color);
drawPixel(x0 + r, y0, color);
drawPixel(x0 - r, y0, color);
while (x<y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
drawPixel(x0 + x, y0 + y, color);
drawPixel(x0 - x, y0 + y, color);
drawPixel(x0 + x, y0 - y, color);
drawPixel(x0 - x, y0 - y, color);
drawPixel(x0 + y, y0 + x, color);
drawPixel(x0 - y, y0 + x, color);
drawPixel(x0 + y, y0 - x, color);
drawPixel(x0 - y, y0 - x, color);
}
}
void Display::drawCircleHelper(int16_t x0, int16_t y0,
int16_t r, uint8_t cornername, uint16_t color) {
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
while (x<y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
if (cornername & 0x4) {
drawPixel(x0 + x, y0 + y, color);
drawPixel(x0 + y, y0 + x, color);
}
if (cornername & 0x2) {
drawPixel(x0 + x, y0 - y, color);
drawPixel(x0 + y, y0 - x, color);
}
if (cornername & 0x8) {
drawPixel(x0 - y, y0 + x, color);
drawPixel(x0 - x, y0 + y, color);
}
if (cornername & 0x1) {
drawPixel(x0 - y, y0 - x, color);
drawPixel(x0 - x, y0 - y, color);
}
}
}
void Display::fillCircle(int16_t x0, int16_t y0, int16_t r,
uint16_t color) {
drawFastVLine(x0, y0 - r, 2 * r + 1, color);
fillCircleHelper(x0, y0, r, 3, 0, color);
}
// Used to do circles and roundrects
void Display::fillCircleHelper(int16_t x0, int16_t y0, int16_t r,
uint8_t cornername, int16_t delta, uint16_t color) {
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
while (x<y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
if (cornername & 0x1) {
drawFastVLine(x0 + x, y0 - y, 2 * y + 1 + delta, color);
drawFastVLine(x0 + y, y0 - x, 2 * x + 1 + delta, color);
}
if (cornername & 0x2) {
drawFastVLine(x0 - x, y0 - y, 2 * y + 1 + delta, color);
drawFastVLine(x0 - y, y0 - x, 2 * x + 1 + delta, color);
}
}
}
void Display::drawRoundRect(int16_t x, int16_t y, int16_t w,
int16_t h, int16_t r, uint16_t color) {
// smarter version
drawFastHLine(x + r, y, w - 2 * r, color); // Top
drawFastHLine(x + r, y + h - 1, w - 2 * r, color); // Bottom
drawFastVLine(x, y + r, h - 2 * r, color); // Left
drawFastVLine(x + w - 1, y + r, h - 2 * r, color); // Right
// draw four corners
drawCircleHelper(x + r, y + r, r, 1, color);
drawCircleHelper(x + w - r - 1, y + r, r, 2, color);
drawCircleHelper(x + w - r - 1, y + h - r - 1, r, 4, color);
drawCircleHelper(x + r, y + h - r - 1, r, 8, color);
}
// Fill a rounded rectangle
void Display::fillRoundRect(int16_t x, int16_t y, int16_t w,
int16_t h, int16_t r, uint16_t color) {
// smarter version
fillRect(x + r, y, w - 2 * r, h, color);
// draw four corners
fillCircleHelper(x + w - r - 1, y + r, r, 1, h - 2 * r - 1, color);
fillCircleHelper(x + r, y + r, r, 2, h - 2 * r - 1, color);
}
void Display::drawTriangle(int16_t x0, int16_t y0,
int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color) {
drawLine(x0, y0, x1, y1, color);
drawLine(x1, y1, x2, y2, color);
drawLine(x2, y2, x0, y0, color);
}
// Fill a triangle
void Display::fillTriangle(int16_t x0, int16_t y0,
int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color) {
int16_t a, b, y, last;
// Sort coordinates by Y order (y2 >= y1 >= y0)
if (y0 > y1) {
_swap_int16_t(y0, y1); _swap_int16_t(x0, x1);
}
if (y1 > y2) {
_swap_int16_t(y2, y1); _swap_int16_t(x2, x1);
}
if (y0 > y1) {
_swap_int16_t(y0, y1); _swap_int16_t(x0, x1);
}
if (y0 == y2) { // Handle awkward all-on-same-line case as its own thing
a = b = x0;
if (x1 < a) a = x1;
else if (x1 > b) b = x1;
if (x2 < a) a = x2;
else if (x2 > b) b = x2;
drawFastHLine(a, y0, b - a + 1, color);
return;
}
int16_t
dx01 = x1 - x0,
dy01 = y1 - y0,
dx02 = x2 - x0,
dy02 = y2 - y0,
dx12 = x2 - x1,
dy12 = y2 - y1;
int32_t
sa = 0,
sb = 0;
// For upper part of triangle, find scanline crossings for segments
// 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1
// is included here (and second loop will be skipped, avoiding a /0
// error there), otherwise scanline y1 is skipped here and handled
// in the second loop...which also avoids a /0 error here if y0=y1
// (flat-topped triangle).
if (y1 == y2) last = y1; // Include y1 scanline
else last = y1 - 1; // Skip it
for (y = y0; y <= last; y++) {
a = x0 + sa / dy01;
b = x0 + sb / dy02;
sa += dx01;
sb += dx02;
/* longhand:
a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if (a > b) _swap_int16_t(a, b);
drawFastHLine(a, y, b - a + 1, color);
}
// For lower part of triangle, find scanline crossings for segments
// 0-2 and 1-2. This loop is skipped if y1=y2.
sa = dx12 * (y - y1);
sb = dx02 * (y - y0);
for (; y <= y2; y++) {
a = x1 + sa / dy12;
b = x0 + sb / dy02;
sa += dx12;
sb += dx02;
/* longhand:
a = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if (a > b) _swap_int16_t(a, b);
drawFastHLine(a, y, b - a + 1, color);
}
}
boolean Display::getBitmapPixel(const uint8_t* bitmap, uint8_t x, uint8_t y){
return pgm_read_byte(bitmap+2 + y * ((pgm_read_byte(bitmap)+7)/8) + (x >> 3)) & (B10000000 >> (x % 8));
}
// Draw a 1-bit image (bitmap) at the specified (x,y) position from the
// provided bitmap buffer (must be PROGMEM memory) using the specified
// foreground color (unset bits are transparent).
void Adafruit_GFX::drawBitmap(int16_t x, int16_t y,
const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) {
int16_t i, j, byteWidth = (w + 7) / 8;
uint8_t byte;
for (j = 0; j<h; j++) {
for (i = 0; i<w; i++) {
if (i & 7) byte <<= 1;
else byte = pgm_read_byte(bitmap + j * byteWidth + i / 8);
if (byte & 0x80) drawPixel(x + i, y + j, color);
}
}
}
// Draw a 1-bit image (bitmap) at the specified (x,y) position from the
// provided bitmap buffer (must be PROGMEM memory) using the specified
// foreground (for set bits) and background (for clear bits) colors.
void Display::drawBitmap(int16_t x, int16_t y,
const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg) {
int16_t i, j, byteWidth = (w + 7) / 8;
uint8_t byte;
for (j = 0; j<h; j++) {
for (i = 0; i<w; i++) {
if (i & 7) byte <<= 1;
else byte = pgm_read_byte(bitmap + j * byteWidth + i / 8);
if (byte & 0x80) drawPixel(x + i, y + j, color);
else drawPixel(x + i, y + j, bg);
}
}
}
// drawBitmap() variant for RAM-resident (not PROGMEM) bitmaps.
void Display::drawBitmap(int16_t x, int16_t y,
uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) {
int16_t i, j, byteWidth = (w + 7) / 8;
uint8_t byte;
for (j = 0; j<h; j++) {
for (i = 0; i<w; i++) {
if (i & 7) byte <<= 1;
else byte = bitmap[j * byteWidth + i / 8];
if (byte & 0x80) drawPixel(x + i, y + j, color);
}
}
}
// drawBitmap() variant w/background for RAM-resident (not PROGMEM) bitmaps.
void Display::drawBitmap(int16_t x, int16_t y,
uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg) {
int16_t i, j, byteWidth = (w + 7) / 8;
uint8_t byte;
for (j = 0; j<h; j++) {
for (i = 0; i<w; i++) {
if (i & 7) byte <<= 1;
else byte = bitmap[j * byteWidth + i / 8];
if (byte & 0x80) drawPixel(x + i, y + j, color);
else drawPixel(x + i, y + j, bg);
}
}
}
void Display::drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet){
drawTilemap(x,y,tilemap,spritesheet,0,0,LCDWIDTH,LCDHEIGHT);
}
void Display::drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet,uint8_t dx,uint8_t dy,uint8_t dw,uint8_t dh){
uint8_t tilemap_width = pgm_read_byte(tilemap);
uint8_t tilemap_height = pgm_read_byte(tilemap + 1);
uint8_t tile_width = pgm_read_byte(tilemap + 2);
uint8_t tile_height = pgm_read_byte(tilemap + 3);
tilemap += 4; // now the first tiyleis at tilemap
uint8_t ddw = dw + dx;
uint8_t ddh = dh + dy;
uint8_t maxDdx = (dw - x + tile_width - 1) / tile_width;
uint8_t maxDdy = (dh - y + tile_height - 1) / tile_height;
if(tilemap_width < maxDdx){
maxDdx = tilemap_width;
}
if(tilemap_height < maxDdy){
maxDdy = tilemap_height;
}
int8_t startDdx = (-x) / tile_width;
int8_t startDdy = (-y) / tile_height;
if(startDdx < 0){
startDdx = 0;
}
if(startDdy < 0){
startDdy = 0;
}
if(flagcollision)numcolision = 0; //Line 735 - clear numcolision - ADD by Summoner123
for(uint8_t ddy = startDdy;ddy < maxDdy;ddy++){
for(uint8_t ddx = startDdx;ddx < maxDdx;ddx++){
int8_t drawX = ddx*tile_width + x + dx;
int8_t drawY = ddy*tile_height + y + dy;
uint8_t tile = pgm_read_byte(tilemap + ddy*tilemap_width + ddx);
if(drawX >= dx && drawY >= dy && drawX <= (ddw-tile_width) && drawY <= (ddh-tile_height)){
drawBitmap(drawX,drawY,tile_width,tile_height,spritesheet[tile]);
if(flagcollision){
solid[numcolision].x = drawX; //Save X coordinate - ADD by Summoner123
solid[numcolision].y = drawY; //Save Y coordinate - ADD by Summoner123
solid[numcolision].spritecol = spritesheet[tile]; //Save Sprite of tile - ADD by Summoner123
numcolision++; //Increment numcolision - ADD by Summoner123
}
}else{ // we need to draw a partial bitmap
drawBitmap(drawX,drawY,tile_width,tile_height,spritesheet[tile],dx,dy,dw,dh);
}
}
}
}
#if ARDUINO >= 100
size_t Display::write(uint8_t c) {
#else
void Display::write(uint8_t c) {
#endif
if (c == '\n') {
cursorY += fontSize * fontHeight;
cursorX = 0;
} else if (c == '\r') {
// skip em
} else {
drawChar(cursorX, cursorY, c, fontSize);
cursorX += fontSize * fontWidth;
if (textWrap && (cursorX > (LCDWIDTH - fontSize * fontWidth))) {
cursorY += fontSize * fontHeight;
cursorX = 0;
}
}
#if ARDUINO >= 100
return 1;
#endif
}
void Display::setFont(const GFXfont *f) {
if (f) { // Font struct pointer passed in?
if (!gfxFont) { // And no current font struct?
// Switching from classic to new font behavior.
// Move cursor pos down 6 pixels so it's on baseline.
cursor_y += 6;
}
}
else if (gfxFont) { // NULL passed. Current font struct defined?
// Switching from new to classic font behavior.
// Move cursor pos up 6 pixels so it's at top-left of char.
cursor_y -= 6;
}
gfxFont = (GFXfont *)f;
}
// Draw a character
void Display::drawChar(int16_t x, int16_t y, unsigned char c,
uint16_t color, uint16_t bg, uint8_t size) {
if (!gfxFont) { // 'Classic' built-in font
if ((x >= _width) || // Clip right
(y >= _height) || // Clip bottom
((x + 6 * size - 1) < 0) || // Clip left
((y + 8 * size - 1) < 0)) // Clip top
return;
if (!_cp437 && (c >= 176)) c++; // Handle 'classic' charset behavior
for (int8_t i = 0; i<6; i++) {
uint8_t line;
if (i < 5) line = pgm_read_byte(font + (c * 5) + i);
else line = 0x0;
for (int8_t j = 0; j<8; j++, line >>= 1) {
if (line & 0x1) {
if (size == 1) drawPixel(x + i, y + j, color);
else fillRect(x + (i*size), y + (j*size), size, size, color);
}
else if (bg != color) {
if (size == 1) drawPixel(x + i, y + j, bg);
else fillRect(x + i*size, y + j*size, size, size, bg);
}
}
}
}
else { // Custom font
// Character is assumed previously filtered by write() to eliminate
// newlines, returns, non-printable characters, etc. Calling drawChar()
// directly with 'bad' characters of font may cause mayhem!
c -= pgm_read_byte(&gfxFont->first);
GFXglyph *glyph = &(((GFXglyph *)pgm_read_pointer(&gfxFont->glyph))[c]);
uint8_t *bitmap = (uint8_t *)pgm_read_pointer(&gfxFont->bitmap);
uint16_t bo = pgm_read_word(&glyph->bitmapOffset);
uint8_t w = pgm_read_byte(&glyph->width),
h = pgm_read_byte(&glyph->height),
xa = pgm_read_byte(&glyph->xAdvance);
int8_t xo = pgm_read_byte(&glyph->xOffset),
yo = pgm_read_byte(&glyph->yOffset);
uint8_t xx, yy, bits, bit = 0;
int16_t xo16, yo16;
if (size > 1) {
xo16 = xo;
yo16 = yo;
}
// Todo: Add character clipping here
// NOTE: THERE IS NO 'BACKGROUND' COLOR OPTION ON CUSTOM FONTS.
// THIS IS ON PURPOSE AND BY DESIGN. The background color feature
// has typically been used with the 'classic' font to overwrite old
// screen contents with new data. This ONLY works because the
// characters are a uniform size; it's not a sensible thing to do with
// proportionally-spaced fonts with glyphs of varying sizes (and that
// may overlap). To replace previously-drawn text when using a custom
// font, use the getTextBounds() function to determine the smallest
// rectangle encompassing a string, erase the area with fillRect(),
// then draw new text. This WILL infortunately 'blink' the text, but
// is unavoidable. Drawing 'background' pixels will NOT fix this,
// only creates a new set of problems. Have an idea to work around
// this (a canvas object type for MCUs that can afford the RAM and
// displays supporting setAddrWindow() and pushColors()), but haven't
// implemented this yet.
for (yy = 0; yy<h; yy++) {
for (xx = 0; xx<w; xx++) {
if (!(bit++ & 7)) {
bits = pgm_read_byte(&bitmap[bo++]);
}
if (bits & 0x80) {
if (size == 1) {
drawPixel(x + xo + xx, y + yo + yy, color);
}
else {
fillRect(x + (xo16 + xx)*size, y + (yo16 + yy)*size, size, size, color);
}
}
bits <<= 1;
}
}
} // End classic vs custom font
}
/*********************************º¯Êý******************************/
uint16_t RGB(uint16_t r, uint16_t g, uint16_t b)
{
uint16_t rgb = 0;
r *= 31;
r /= 255;
g *= 63;
g /= 255;
b *= 31;
b /= 255;
rgb |= (r << 11);
rgb |= (g << 6);
rgb |= b;
return rgb;
}
sketch
- Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
#define GREEN 0x0400
const byte green_square[] PROGMEM ={16,16,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,
B11111111,B11111111,};
void setup() {
gb.begin();
gb.titleScreen(F("test"));
}
void loop() {
if(gb.update()){
gb.display.drawBitmap(70, 70, green_square, 16,16, GREEN);
}
}
I could really use some advice about the pcd8544 stuff. im pretty sure my screen doesn't use this since its about the 5110.
Edit: fixed the width and height stuff now I'm stuck on the rotation. I don't know exactly what it's asking for so I don't know how to correct it.
Edit: solved the rotation problem and now the H file compiles. Yay now I have the cpp file to debug!!!
-
Duhjoker
-
- Posts: 446
- Joined: Sat Jul 02, 2016 4:57 am
- Location: Where Palm trees grow
Return to Programming Questions
Who is online
Users browsing this forum: No registered users and 60 guests