Skip to content

Instantly share code, notes, and snippets.

@houmei
Created May 14, 2014 15:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Adafruit 1.8" TFT Shield HardwareSPI/SoftwareSPI
#include "TFT.h"
#if (USB_VID == 0x2341) && (USB_PID == 0x803C) // are we building for Esplora?
TFT EsploraTFT(7, 0, 1);
#endif
TFT::TFT(uint8_t CS, uint8_t RS, uint8_t RST)
: Adafruit_ST7735(CS, RS, RST)
{
// as we already know the orientation (landscape, therefore rotated),
// set default width and height without need to call begin() first.
_width = ST7735_TFTHEIGHT;
_height = ST7735_TFTWIDTH;
}
TFT::TFT(uint8_t CS, uint8_t RS, uint8_t SID, uint8_t SCLK, uint8_t RST)
: Adafruit_ST7735(CS, RS, SID, SCLK, RST)
{
// as we already know the orientation (landscape, therefore rotated),
// set default width and height without need to call begin() first.
_width = ST7735_TFTHEIGHT;
_height = ST7735_TFTWIDTH;
}
void TFT::begin() {
initR(INITR_REDTAB);
setRotation(1);
}
#ifndef _ARDUINO_TFT_H
#define _ARDUINO_TFT_H
#include "Arduino.h"
#include "utility/Adafruit_GFX.h"
#include "utility/Adafruit_ST7735.h"
/// The Arduino LCD is a ST7735-based device.
/// By default, it is mounted horizontally.
/// TFT class follows the convention of other
/// Arduino library classes by adding a begin() method
/// to be called in the setup() routine.
/// @author Enrico Gueli <enrico.gueli@gmail.com>
class TFT : public Adafruit_ST7735 {
public:
TFT(uint8_t CS, uint8_t RS, uint8_t RST);
TFT(uint8_t CS, uint8_t RS, uint8_t SID, uint8_t SCLK, uint8_t RST);
void begin();
};
/// Esplora boards have hard-wired connections with
/// the Arduino LCD if mounted on the onboard connector.
#if (USB_VID == 0x2341) && (USB_PID == 0x803C) // are we building for Esplora?
extern TFT EsploraTFT;
#endif
#endif // _ARDUINO_TFT_H
/*
TFT demo
https://github.com/arduino/TFT
http://arduino.cc/en/Reference/TFTLibrary
*/
// randomdot
#include <TFT.h>
#include <SPI.h>
#define TFT_CS 10
#define TFT_DC 8
#define TFT_RST 0
#define TFT_SCLK 13
#define TFT_MOSI 11
#define SD_CS 4
TFT screen = TFT(TFT_CS, TFT_DC, TFT_RST); // for UNO
// TFT screen = TFT(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST); // for Leonardo
void setup(void) {
Serial.begin(9600);
while(!Serial);
Serial.println("START");
screen.begin();
screen.background(0,0,0);
screen.fill(255,255,255);
}
const int XMAX=ST7735_TFTHEIGHT;
const int YMAX=ST7735_TFTWIDTH;
void loop() {
int x1,y1,x2,y2,r,g,b;
unsigned long stime,etime;
stime=millis();
for(int i=1;i<=1000;i++) {
r=random(256);
g=random(256);
b=random(256);
x1=random(0,XMAX);
y1=random(0,YMAX);
x2=random(0,XMAX);
y2=random(0,YMAX);
screen.stroke(r,g,b);
screen.line(x1,y1,x2,y2);
}
etime=millis();
Serial.println(etime-stime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment