Skip to content

Commit

Permalink
add demo for 2.7" v2 shield
Browse files Browse the repository at this point in the history
  • Loading branch information
ladyada committed Dec 17, 2023
1 parent 512bbbc commit 01008ab
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/***************************************************
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.
MIT license, all text above must be included in any redistribution
****************************************************/

#include "Adafruit_ThinkInk.h"

#define EPD_CS 10
#define EPD_DC 9
#define SRAM_CS 8
#define EPD_BUSY -1
#define EPD_RESET -1
#define EPD_SPI &SPI // primary SPI

// 2.7" Tricolor Featherwing or Breakout with EK79686 chipset (v2 Black Shield)
ThinkInk_270_Tricolor_Z70 display(EPD_DC, EPD_RESET, EPD_CS, SRAM_CS,
EPD_BUSY, EPD_SPI);

#include <Adafruit_XCA9554.h>
Adafruit_XCA9554 expander;
#define XCA_EPD_RESET 5
#define XCA_EPD_CARDDET 6
#define XCA_EPD_BUSY 7

void expanderEPDReset(void) {
expander.pinMode(XCA_EPD_RESET, OUTPUT);
expander.digitalWrite(XCA_EPD_RESET, HIGH); // start high for sure
delay(10);
expander.digitalWrite(XCA_EPD_RESET, LOW); // enter reset
delay(10);
expander.digitalWrite(XCA_EPD_RESET, HIGH); // bring out of reset
delay(10);
}

bool expanderEPDBusy(void) {
expander.pinMode(XCA_EPD_BUSY, INPUT);
return expander.digitalRead(XCA_EPD_BUSY);
}

void setup() {
Serial.begin(115200);
while (!Serial) {
delay(10);
}
Serial.println("Adafruit ThinkInk Shield test in red/black/white");

// Begin communication with the expander
if (!expander.begin(0x20)) { // Replace with actual I2C address if different
Serial.println("Failed to find XCA9554 chip");
while (1);
}
display.setCustomBusyFunction(expanderEPDBusy);
display.setCustomResetFunction(expanderEPDReset);
display.begin(THINKINK_TRICOLOR);

display.clearBuffer();
display.setTextSize(2);
display.setCursor(10, (display.height() - 24) / 2);
display.setTextColor(EPD_BLACK);
display.print("Press the ");
display.setTextColor(EPD_RED);
display.print("Buttons!");
display.display();

// set the 4 buttons to inputs via the expander
expander.pinMode(0, INPUT);
expander.pinMode(1, INPUT);
expander.pinMode(2, INPUT);
expander.pinMode(3, INPUT);
}

void loop() {
if (! expander.digitalRead(0)) {
Serial.println("Button A pressed");
Serial.println("Banner demo");
display.clearBuffer();
display.setTextSize(3);
display.setCursor((display.width() - 144) / 2, (display.height() - 24) / 2);
display.setTextColor(EPD_BLACK);
display.print("Tri");
display.setTextColor(EPD_RED);
display.print("Color");
display.display();
}

if (! expander.digitalRead(1)) {
Serial.println("Button B pressed");
Serial.println("Color rectangle demo");
display.clearBuffer();
display.fillRect(display.width() / 3, 0, display.width() / 3,
display.height(), EPD_BLACK);
display.fillRect((display.width() * 2) / 3, 0, display.width() / 3,
display.height(), EPD_RED);
display.display();
}

if (! expander.digitalRead(2)) {
Serial.println("Button C pressed");
Serial.println("Text demo");
// large block of text
display.clearBuffer();
display.setTextSize(1);
testdrawtext(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur "
"adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, "
"fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor "
"neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet "
"ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a "
"tortor imperdiet posuere. ",
EPD_BLACK);
display.display();
}

if (! expander.digitalRead(3)) {
Serial.println("Button D pressed");
display.clearBuffer();
for (int16_t i = 0; i < display.width(); i += 4) {
display.drawLine(0, 0, i, display.height() - 1, EPD_BLACK);
}

for (int16_t i = 0; i < display.height(); i += 4) {
display.drawLine(display.width() - 1, 0, 0, i, EPD_RED);
}
display.display();
}
}

void testdrawtext(const char *text, uint16_t color) {
display.setCursor(0, 0);
display.setTextColor(color);
display.setTextWrap(true);
display.print(text);
}
1 change: 1 addition & 0 deletions src/Adafruit_ThinkInk.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "panels/ThinkInk_213_Grayscale4_T5.h"
#include "panels/ThinkInk_270_Grayscale4_W3.h"
#include "panels/ThinkInk_290_Grayscale4_T5.h"
#include "panels/ThinkInk_290_Grayscale4_T94.h"
#include "panels/ThinkInk_420_Grayscale4_T2.h"

#include "panels/ThinkInk_154_Mono_D27.h"
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/Adafruit_EK79686.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Adafruit_EK79686::Adafruit_EK79686(int width, int height, int16_t DC,
*/
/**************************************************************************/
void Adafruit_EK79686::busy_wait(void) {
if (_busy_pin >= 0) {
if (_busy_pin >= 0 || _customBusyFunction != NULL) {
do {
EPD_command(EK79686_FLG);
delay(10);
Expand Down

0 comments on commit 01008ab

Please sign in to comment.