Created
November 12, 2015 20:18
-
-
Save robertcedwards/a5d6afb74ae41353f06a to your computer and use it in GitHub Desktop.
Gist for Particle.io Photon to display an image on Sharp Memory LCD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************************* | |
This is an example sketch for our Monochrome SHARP Memory Displays | |
Pick one up today in the adafruit shop! | |
------> http://www.adafruit.com/products/1393 | |
These displays use SPI to communicate, 3 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 must be included in any redistribution | |
*********************************************************************/ | |
#include "fonts.h" | |
#include "Adafruit_mfGFX.h" | |
#include "Adafruit_SharpMem.h" | |
/********************************************************************* | |
Our pin setup for the Spark | |
CLK = pin A3 | |
DI = pin A5 | |
CS = pin A1 | |
To convert your image to a Bitmap make the image 96px x 96px in a program like Photoshop. | |
One the image is the correct size go to http://www.digole.com/tools/PicturetoC_Hex_converter.php | |
to convert your image to a hex value like shown below. | |
*********************************************************************/ | |
Adafruit_SharpMem display(SCK, MOSI, A1); //SCK, MOSI, SS | |
#define BLACK 0 | |
#define WHITE 1 | |
//Dustins Words custom bitmap | |
const uint8_t qr[] = { | |
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,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,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,0xf8,0x07,0xf0,0x00,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x00,0x1f,0xff,0x3f,0xfe,0x00,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x00,0x7c,0x03,0xf8,0x07,0x80,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x00,0xe0,0x00,0xf0,0x01,0xe0,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x03,0x80,0x00,0x38,0x00,0x70,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x07,0x00,0x00,0x1c,0x00,0x38,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x06,0x00,0x00,0x0c,0x00,0x1c,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x0c,0x00,0x00,0x06,0x00,0x0c,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x1c,0x00,0x00,0x03,0x00,0x06,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x18,0x00,0x00,0x03,0x00,0x06,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x38,0x00,0x00,0x01,0x80,0x03,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x30,0x00,0x00,0x01,0x80,0x03,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x30,0x00,0x00,0x01,0x80,0x01,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0xc0,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0xc0,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0xc0,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0xc0,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0xc0,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0xc0,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x80,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x00,0x30,0x00,0x00,0x01,0x80,0x03,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x30,0x00,0x00,0x01,0x80,0x03,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x18,0x00,0x00,0x03,0x00,0x03,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x18,0x00,0x00,0x03,0x00,0x06,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x0c,0x00,0x00,0x06,0x00,0x0e,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x0e,0x00,0x00,0x0e,0x00,0x0c,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x07,0x00,0x00,0x1c,0x00,0x18,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x03,0x80,0x00,0x38,0x00,0x30,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x01,0xc0,0x00,0x70,0x00,0xe0,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x00,0xf0,0x01,0xf0,0x03,0xc0,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x00,0x3f,0xbf,0xff,0x7f,0xc0,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xf0,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x00,0x7e,0x00,0x00,0x00,0x7c,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x01,0xe0,0x00,0x00,0x00,0x0e,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x06,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00 | |
,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x00,0xc0,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x00 | |
,0x00,0x00,0x00,0xc0,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x00 | |
,0x00,0x00,0x00,0xc0,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x1d,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x87,0xff,0xff,0xff,0xff,0xf9,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x9f,0xff,0xff,0xff,0xff,0xc1,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0xb8,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0xe0,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0xc0,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0xc0,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0xc0,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0xc0,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0xe0,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0xb8,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x9f,0xff,0xff,0xff,0x80,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x87,0xff,0xff,0xff,0x80,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
,0x00,0x00,0x01,0x80,0x00,0x00,0xc0,0x00,0x01,0x80,0x00,0x00 | |
}; | |
void setup(void) | |
{ | |
SPI.begin(); | |
SPI.setBitOrder(MSBFIRST); | |
SPI.setDataMode(SPI_MODE0); | |
SPI.setClockDivider(SPI_CLOCK_DIV16); | |
display.init(); // Initialize the hardware ports since cannot be done in class instantation above | |
Serial.begin(9600); | |
Serial.println("Hello!"); | |
// start & clear the display | |
display.begin(); | |
display.clearDisplay(); | |
// draw a single pixel | |
display.drawPixel(10, 10, BLACK); | |
display.refresh(); | |
delay(500); | |
display.clearDisplay(); | |
// draw many lines | |
testdrawline(); | |
delay(500); | |
display.clearDisplay(); | |
// draw rectangles | |
testdrawrect(); | |
delay(500); | |
display.clearDisplay(); | |
// draw multiple rectangles | |
testfillrect(); | |
display.refresh(); | |
delay(500); | |
display.clearDisplay(); | |
// draw a circle, 10 pixel radius | |
display.fillCircle(display.width()/2, display.height()/2, 10, BLACK); | |
display.refresh(); | |
delay(500); | |
display.clearDisplay(); | |
testdrawroundrect(); | |
display.refresh(); | |
delay(500); | |
display.clearDisplay(); | |
testfillroundrect(); | |
display.refresh(); | |
delay(500); | |
display.clearDisplay(); | |
testdrawtriangle(); | |
display.refresh(); | |
delay(500); | |
display.clearDisplay(); | |
testfilltriangle(); | |
display.refresh(); | |
delay(500); | |
display.clearDisplay(); | |
// draw the first ~12 characters in the font | |
testdrawchar(); | |
display.refresh(); | |
delay(500); | |
display.clearDisplay(); | |
// text display tests | |
display.setTextSize(2); | |
display.setTextColor(BLACK); | |
display.setCursor(0,0); | |
delay(500); | |
//Our custom image | |
//display.println("Hello, Dustin's Words!"); | |
display.drawBitmap(0,0,qr,96,96,0); // This is the custom bitmap call | |
display.refresh(); | |
delay(500); | |
//Spark.variable("qr", &qr, INT); | |
//Spark.publish("icon",qr); | |
} | |
void loop(void) | |
{ | |
// Screen must be refreshed at least once per second | |
display.refresh(); | |
delay(500); | |
} | |
/// | |
void testdrawchar(void) { | |
display.setTextSize(1); | |
display.setTextColor(BLACK); | |
display.setCursor(0,0); | |
for (uint8_t i=0; i < 168; i++) { | |
if (i == '\n') continue; | |
display.write(i); | |
//if ((i > 0) && (i % 14 == 0)) | |
//display.println(); | |
} | |
display.refresh(); | |
} | |
void testdrawcircle(void) { | |
for (uint8_t i=0; i<display.height(); i+=2) { | |
display.drawCircle(display.width()/2-5, display.height()/2-5, i, BLACK); | |
display.refresh(); | |
} | |
} | |
void testfillrect(void) { | |
uint8_t color = 1; | |
for (uint8_t i=0; i<display.height()/2; i+=3) { | |
// alternate colors | |
display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2); | |
display.refresh(); | |
color++; | |
} | |
} | |
void testdrawtriangle(void) { | |
for (uint16_t i=0; i<min(display.width(),display.height())/2; i+=5) { | |
display.drawTriangle(display.width()/2, display.height()/2-i, | |
display.width()/2-i, display.height()/2+i, | |
display.width()/2+i, display.height()/2+i, BLACK); | |
display.refresh(); | |
} | |
} | |
void testfilltriangle(void) { | |
uint8_t color = BLACK; | |
for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) { | |
display.fillTriangle(display.width()/2, display.height()/2-i, | |
display.width()/2-i, display.height()/2+i, | |
display.width()/2+i, display.height()/2+i, color); | |
if (color == WHITE) color = BLACK; | |
else color = WHITE; | |
display.refresh(); | |
} | |
} | |
void testdrawroundrect(void) { | |
for (uint8_t i=0; i<display.height()/4; i+=2) { | |
display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, BLACK); | |
display.refresh(); | |
} | |
} | |
void testfillroundrect(void) { | |
uint8_t color = BLACK; | |
for (uint8_t i=0; i<display.height()/4; i+=2) { | |
display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color); | |
if (color == WHITE) color = BLACK; | |
else color = WHITE; | |
display.refresh(); | |
} | |
} | |
void testdrawrect(void) { | |
for (uint8_t i=0; i<display.height()/2; i+=2) { | |
display.drawRect(i, i, display.width()-2*i, display.height()-2*i, BLACK); | |
display.refresh(); | |
} | |
} | |
void testdrawline() { | |
for (uint8_t i=0; i<display.width(); i+=4) { | |
display.drawLine(0, 0, i, display.height()-1, BLACK); | |
display.refresh(); | |
} | |
for (uint8_t i=0; i<display.height(); i+=4) { | |
display.drawLine(0, 0, display.width()-1, i, BLACK); | |
display.refresh(); | |
} | |
delay(250); | |
display.clearDisplay(); | |
for (uint8_t i=0; i<display.width(); i+=4) { | |
display.drawLine(0, display.height()-1, i, 0, BLACK); | |
display.refresh(); | |
} | |
for (int8_t i=display.height()-1; i>=0; i-=4) { | |
display.drawLine(0, display.height()-1, display.width()-1, i, BLACK); | |
display.refresh(); | |
} | |
delay(250); | |
display.clearDisplay(); | |
for (int8_t i=display.width()-1; i>=0; i-=4) { | |
display.drawLine(display.width()-1, display.height()-1, i, 0, BLACK); | |
display.refresh(); | |
} | |
for (int8_t i=display.height()-1; i>=0; i-=4) { | |
display.drawLine(display.width()-1, display.height()-1, 0, i, BLACK); | |
display.refresh(); | |
} | |
delay(250); | |
display.clearDisplay(); | |
for (uint8_t i=0; i<display.height(); i+=4) { | |
display.drawLine(display.width()-1, 0, 0, i, BLACK); | |
display.refresh(); | |
} | |
for (uint8_t i=0; i<display.width(); i+=4) { | |
display.drawLine(display.width()-1, 0, i, display.height()-1, BLACK); | |
display.refresh(); | |
} | |
delay(250); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment