Combined the 2 SSD1351 examples

This commit is contained in:
Melissa LeBlanc-Williams 2019-04-15 21:23:43 -07:00
parent 13f2083f42
commit f315be1ab4
3 changed files with 1 additions and 230 deletions

View file

@ -25,7 +25,7 @@
// Screen dimensions
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 128
#define SCREEN_HEIGHT 128 // Change this to 96 for 1.27" OLED.
// TFT display and SD card share the hardware SPI interface, using
// 'select' pins for each to identify the active device on the bus.
@ -34,8 +34,6 @@
#define TFT_CS 5 // TFT select pin
#define TFT_DC 4 // TFT display/command pin
#define TFT_RST 6 // Or set to -1 and connect to Arduino RESET pin
#define TFT_SCLK 2 // TFT SPI Clock
#define TFT_MOSI 3 // TFT SPI MOSI
Adafruit_SSD1351 tft = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI, TFT_CS, TFT_DC, TFT_RST);

View file

@ -1,128 +0,0 @@
// Adafruit_ImageReader test for Adafruit ST7735 TFT Breakout for Arduino.
// Demonstrates loading images to the screen, to RAM, and how to query
// image file dimensions.
// Requires three BMP files in root directory of SD card:
// rgbwheel.bmp, miniwoof.bmp and wales.bmp.
// As written, this uses the microcontroller's SPI interface for the screen
// (not 'bitbang') and must be wired to specific pins (e.g. for Arduino Uno,
// MOSI = pin 11, MISO = 12, SCK = 13). Other pins are configurable below.
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_SSD1351.h> // Hardware-specific library
#include <Adafruit_ImageReader.h> // Image-reading functions
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
// Screen dimensions
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 96
// TFT display and SD card share the hardware SPI interface, using
// 'select' pins for each to identify the active device on the bus.
#define SD_CS 7 // SD card select pin
#define TFT_CS 5 // TFT select pin
#define TFT_DC 4 // TFT display/command pin
#define TFT_RST 6 // Or set to -1 and connect to Arduino RESET pin
#define TFT_SCLK 2 // TFT SPI Clock
#define TFT_MOSI 3 // TFT SPI MOSI
Adafruit_SSD1351 tft = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI, TFT_CS, TFT_DC, TFT_RST);
Adafruit_ImageReader reader; // Class w/image-reading functions
Adafruit_Image img; // An image loaded into RAM
int32_t width = 0, // BMP image dimensions
height = 0;
void setup(void) {
ImageReturnCode stat; // Status from image-reading functions
Serial.begin(9600);
#if !defined(ESP32)
while(!Serial); // Wait for Serial Monitor before continuing
#endif
tft.begin(); // Initialize screen
Serial.print(F("Initializing SD card..."));
if(!SD.begin(SD_CS)) {
Serial.println(F("failed!"));
for(;;); // Loop here forever
}
Serial.println(F("OK!"));
// Fill screen blue. Not a required step, this just shows that we're
// successfully communicating with the screen.
tft.fillScreen(BLUE);
// Load full-screen BMP file 'rgbwheel.bmp' at position (0,0) (top left).
// Notice the 'reader' object performs this, with 'tft' as an argument.
Serial.print(F("Loading rgbwheel.bmp to screen..."));
stat = reader.drawBMP("/rgbwheel.bmp", tft, 0, -16);
reader.printStatus(stat); // How'd we do?
// Query the dimensions of image 'miniwoof.bmp' WITHOUT loading to screen:
Serial.print(F("Querying miniwoof.bmp image size..."));
stat = reader.bmpDimensions("/miniwoof.bmp", &width, &height);
reader.printStatus(stat); // How'd we do?
if(stat == IMAGE_SUCCESS) { // If it worked, print image size...
Serial.print(F("Image dimensions: "));
Serial.print(width);
Serial.write('x');
Serial.println(height);
}
// Load small BMP 'wales.bmp' into a GFX canvas in RAM. This should fail
// gracefully on Arduino Uno and other small devices, meaning the image
// will not load, but this won't make the program stop or crash, it just
// continues on without it. Should work on Arduino Mega, Zero, etc.
Serial.print(F("Loading wales.bmp to canvas..."));
stat = reader.loadBMP("/wales.bmp", img);
reader.printStatus(stat); // How'd we do?
delay(2000); // Pause 2 seconds before moving on to loop()
}
void loop() {
for(int r=0; r<4; r++) { // For each of 4 rotations...
tft.setRotation(r); // Set rotation
tft.fillScreen(0); // and clear screen
// Load 4 copies of the 'miniwoof.bmp' image to the screen, some
// partially off screen edges to demonstrate clipping. Globals
// 'width' and 'height' were set by bmpDimensions() call in setup().
for(int i=0; i<4; i++) {
reader.drawBMP("/miniwoof.bmp", tft,
(tft.width() * i / 3) - (width / 2),
(tft.height() * i / 3) - (height / 2));
}
delay(1000); // Pause 1 sec.
// Draw 50 Welsh dragon flags in random positions. This has no effect
// on memory-constrained boards like the Arduino Uno, where the image
// failed to load due to insufficient RAM, but it's NOT fatal.
for(int i=0; i<50; i++) {
// Rather than reader.drawBMP() (which works from SD card),
// a different function is used for RAM-resident images:
img.draw(tft, // Pass in tft object
(int16_t)random(-img.width() , tft.width()) , // Horiz pos.
(int16_t)random(-img.height(), tft.height())); // Vert pos
// Reiterating a prior point: img.draw() does nothing and returns
// if the image failed to load. It's unfortunate but not disastrous.
}
delay(2000); // Pause 2 sec.
}
}

View file

@ -1,99 +0,0 @@
/***************************************************
This is a example sketch demonstrating bitmap drawing
capabilities of the SSD1351 library for the 1.5"
and 1.27" 16-bit Color OLEDs with SSD1351 driver chip
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/products/1431
------> http://www.adafruit.com/products/1673
If you're using a 1.27" OLED, change SSD1351HEIGHT in Adafruit_SSD1351.h
to 96 instead of 128
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, all text above must be included in any redistribution
The Adafruit GFX Graphics core library
https://github.com/adafruit/Adafruit-GFX-Library
and Adafruit ImageReader library are also required
https://github.com/adafruit/Adafruit_ImageReader
Be sure to install them!
****************************************************/
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1351.h>
#include <Adafruit_ImageReader.h> // Image-reading functions
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
// Screen dimensions
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 128
// If we are using the hardware SPI interface, these are the pins (for future ref)
#define SCLK_PIN 13
#define MOSI_PIN 11
#define CS_PIN 5
#define RST_PIN 6
#define DC_PIN 4
// to draw images from the SD card, we will share the hardware SPI interface
Adafruit_SSD1351 tft = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI, CS_PIN, DC_PIN, RST_PIN);
// For Arduino Uno/Duemilanove, etc
// connect the SD card with MOSI going to pin 11, MISO going to pin 12 and SCK going to pin 13 (standard)
// Then pin 10 goes to CS (or whatever you have set up)
#define SD_CS 10 // Set the chip select line to whatever you use (10 doesnt conflict with the library)
Adafruit_ImageReader reader; // Class w/image-reading functions
void setup(void) {
ImageReturnCode stat; // Status from image-reading functions
Serial.begin(9600);
pinMode(CS_PIN, OUTPUT);
digitalWrite(CS_PIN, HIGH);
// initialize the OLED
tft.begin();
Serial.println("init");
tft.fillScreen(BLUE);
delay(500);
Serial.print("Initializing SD card...");
if (!SD.begin(SD_CS)) {
Serial.println("failed!");
return;
}
Serial.println("SD OK!");
Serial.print(F("Loading /lily128.bmp to screen..."));
stat = reader.drawBMP("/lily128.bmp", tft, 0, 0);
reader.printStatus(stat); // How'd we do?
}
void loop() {
}