Back to Parent

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_GFX_RK.h>


// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_ST77xx.h"

// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_ST7789.h"

// This #include statement was automatically added by the Particle IDE.
// #include "Adafruit_ST7735.h"


//#include "Adafruit_ST7789.h"
#include "SPI.h"
//#include "Adafruit_GFX.h"

// You can't really have two of these on the same pins, but this is just to make sure it compiles
// It's not a working example.
// I've removed the examples because it's not possible to have dependencies for individual examples
// and the necessary libraries won't be included and the build will fail. Since other boards like
// the miniTFTWing have their own examples, you should just test this library with those examples.

Adafruit_ST7789 st7789(&SPI1, D2, D3, D4);

int buttonPin = D3;
int solPin = D2;
bool displaySmile = false;

bool displaySad = false;
bool displayHeart = false;
bool displayCry = false;
bool displayUnsat = false;

#if defined(ARDUINO_FEATHER_ESP32) // Feather Huzzah32
  #define TFT_CS         14
  #define TFT_RST        15
  #define TFT_DC         32

#elif defined(ESP8266)
  #define TFT_CS         4
  #define TFT_RST        16
  #define TFT_DC         5

#else
  // For the breakout board, you can use any 2 or 3 pins.
  // These pins will also work for the 1.8" TFT shield.
  #define TFT_CS        A5
  #define TFT_RST        -1 // Or set to -1 and connect to Arduino RESET pin
  #define TFT_DC         D8
#endif

// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique
// to each board and not reassignable. For Arduino Uno: MOSI = pin 11 and
// SCLK = pin 13. This is the fastest mode of operation and is required if
// using the breakout board's microSD card.

//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

// OPTION 2 lets you interface the display using ANY TWO or THREE PINS,
// tradeoff being that performance is not as fast as hardware SPI above.
#define TFT_MOSI 11  // Data out
#define TFT_SCLK 13  // Clock out

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);


float p = 3.1415926;

void setup(void) {
  Serial.begin(9600);
  tft.fillScreen(ST77XX_BLACK);

  // Use this initializer (uncomment) if using a 1.3" or 1.54" 240x240 TFT:
  //tft.init(240, 240);           // Init ST7789 240x240

  // OR use this initializer (uncomment) if using a 1.69" 280x240 TFT:
  //tft.init(240, 280);           // Init ST7789 280x240

  // OR use this initializer (uncomment) if using a 2.0" 320x240 TFT:
  //tft.init(240, 320);           // Init ST7789 320x240

  // OR use this initializer (uncomment) if using a 1.14" 240x135 TFT:
  //tft.init(135, 240);           // Init ST7789 240x135
  
  
  // OR use this initializer (uncomment) if using a 1.47" 172x320 TFT:
  tft.init(200, 240);           // Init ST7789 172x320
//   tft.init(320, 320);       //clears screen


  // OR use this initializer (uncomment) if using a 1.9" 170x320 TFT:
  //tft.init(170, 320);           // Init ST7789 170x320

  // SPI speed defaults to SPI_DEFAULT_FREQ defined in the library, you can override it here
  // Note that speed allowable depends on chip and quality of wiring, if you go too fast, you
  // may end up with a black screen some times, or all the time.
  //tft.setSPISpeed(40000000);
  

  // a single pixel
//   tft.drawPixel(tft.width()/2, tft.height()/2, ST77XX_GREEN);
//   delay(500);


    pinMode(buttonPin, INPUT_PULLUP);
  
    Particle.function( "emojiSmile", activateSolenoid );
    Particle.function( "emojiSad", activateSad );
    Particle.function( "emojiHeart", activateHeart );
    Particle.function( "emojiCry", activateCry );
    Particle.function( "emojiUnsat", activateUnsat );
    pinMode(solPin, OUTPUT);
    
}

void loop() {
    
    
    
    if( displaySmile ){
        doSmile(  );
        displaySmile = false;
        
    }
    
    if( displaySad ){
        doSad(  );
        displaySad = false;
    }
    
    if( displayHeart ){
        doHeart(  );
        displayHeart = false;
    }
    
    if( displayCry ){
        doCry(  );
        displayCry = false;
    }
    
    if( displayUnsat ){
        doUnsat(  );
        displayUnsat = false;
    }
}

void doSmile() {
    // digitalWrite(solPin, HIGH);
    tft.fillScreen(ST77XX_BLACK);

    for (int i = 0; i < 2; i++) {
        digitalWrite(solPin, HIGH);
        delay(100);
        digitalWrite(solPin, LOW);
        delay(1000);
    }

    // Wait for the button to be pressed
    while (digitalRead(buttonPin) != LOW) {
        // You can add optional delay here to avoid busy-waiting
        // delay(100);
    }

    // Button is pressed, proceed to displaySmiley
    displaySmiley();
    
}

void doSad(){
    
tft.fillScreen(ST77XX_BLACK);

    for (int i = 0; i < 2; i++) {
        digitalWrite(solPin, HIGH);
        delay(100);
        digitalWrite(solPin, LOW);
        delay(1000);
    }

    // Wait for the button to be pressed
    while (digitalRead(buttonPin) != LOW) {
        // You can add optional delay here to avoid busy-waiting
        // delay(100);
    }

    // Button is pressed, proceed to displaySmiley
    displaySady();
    
}

void doHeart(){
    
tft.fillScreen(ST77XX_BLACK);

    for (int i = 0; i < 2; i++) {
        digitalWrite(solPin, HIGH);
        delay(100);
        digitalWrite(solPin, LOW);
        delay(1000);
    }

    // Wait for the button to be pressed
    while (digitalRead(buttonPin) != LOW) {
        // You can add optional delay here to avoid busy-waiting
        // delay(100);
    }

    // Button is pressed, proceed to displaySmiley
    displayHearty();
    
}

void doCry(){
    
tft.fillScreen(ST77XX_BLACK);

    for (int i = 0; i < 2; i++) {
        digitalWrite(solPin, HIGH);
        delay(100);
        digitalWrite(solPin, LOW);
        delay(1000);
    }

    // Wait for the button to be pressed
    while (digitalRead(buttonPin) != LOW) {
        // You can add optional delay here to avoid busy-waiting
        // delay(100);
    }

    // Button is pressed, proceed to displaySmiley
    displayCryFace();
    
}

void doUnsat(){
    
tft.fillScreen(ST77XX_BLACK);

    for (int i = 0; i < 2; i++) {
        digitalWrite(solPin, HIGH);
        delay(100);
        digitalWrite(solPin, LOW);
        delay(1000);
    }

    // Wait for the button to be pressed
    while (digitalRead(buttonPin) != LOW) {
        // You can add optional delay here to avoid busy-waiting
        // delay(100);
    }

    // Button is pressed, proceed to displaySmiley
    displayUnsatFace();
    
}

int activateCry( String command ){
    displayCry = true;
    return 1;
    
}

int activateUnsat( String command ){
    displayUnsat = true;
    return 1;
    
}

int activateHeart( String command ){
    displayHeart = true;
    return 1;
    
}

int activateSolenoid( String command ){
    displaySmile = true;
    return 1;
    
}
    
int activateSad( String command ){
    displaySad = true;
    return 1;

}

void displayCryFace() {
  // draw face
  tft.fillScreen(ST77XX_BLACK);
  tft.fillCircle(120, 120, 50, ST77XX_YELLOW);
  
  //draw mouth
  tft.fillCircle(145, 120, 18, ST77XX_BLACK);

  // draw left eye

  tft.fillCircle(110, 145, 15, ST77XX_BLACK);  // Swap X and Y coordinates and adjust
  tft.fillCircle(110, 145, 5, ST77XX_YELLOW);  // Swap X and Y coordinates and adjust
  tft.fillRect(110, 120, 22.5, 41, ST77XX_YELLOW);  // Swap X and Y coordinates and adjust
  
  // draw right eye
  tft.fillCircle(110, 105, 15, ST77XX_BLACK);  // Swap X and Y coordinates and adjust
  tft.fillCircle(110, 105, 5, ST77XX_YELLOW);  // Swap X and Y coordinates and adjust
  tft.fillRect(110, 80, 22.5, 41, ST77XX_YELLOW);  // Swap X and Y coordinates and adjust
  
  tft.fillRect(105, 145, 120, 10, ST77XX_BLUE);  // Swap X and Y coordinates
  tft.fillRect(105, 95, 120, 10, ST77XX_BLUE);  // Swap X and Y coordinates

}

void displayUnsatFace() {
  // draw face
  tft.fillScreen(ST77XX_BLACK);
  tft.fillCircle(120, 120, 50, ST77XX_YELLOW);

  // draw mouth (unsatisfied)
  tft.fillRect(140, 100, 12.5, 45, ST77XX_BLACK);  // Adjust Y coordinate and size for unsatisfied mouth

  for (int i = 0; i < 5; ++i) {
  // draw eyes (horizontal rectangles for unsatisfied eyes)
  tft.fillRect(100, 95, 20, 10, ST77XX_BLACK);   // Adjust X, Y coordinates, and size for left eye
  tft.fillRect(100, 135, 20, 10, ST77XX_BLACK);  // Adjust X, Y coordinates, and size for right eye
  
  delay(300);
  
  tft.fillRect(100, 95, 20, 10, ST77XX_YELLOW);   // Adjust X, Y coordinates, and size for left eye
  tft.fillRect(100, 135, 20, 10, ST77XX_YELLOW);  // Adjust X, Y coordinates, and size for right eye  
  
  delay(100);
  
  tft.fillRect(110, 90, 10, 20, ST77XX_BLACK);   // Adjust X, Y coordinates, and size for right eye
  tft.fillRect(110, 140, 10, 20, ST77XX_BLACK);  // Adjust X, Y coordinates, and size for left eye
  
  delay(1000);
  
  tft.fillRect(110, 90, 10, 20, ST77XX_YELLOW);   // Adjust X, Y coordinates, and size for right eye
  tft.fillRect(110, 140, 10, 20, ST77XX_YELLOW);  // Adjust X, Y coordinates, and size for left eye
  
  delay(150);
  
  }
  
  tft.fillRect(110, 90, 10, 20, ST77XX_BLACK);   // Adjust X, Y coordinates, and size for right eye
  tft.fillRect(110, 140, 10, 20, ST77XX_BLACK);  // Adjust X, Y coordinates, and size for left eye
  
}

void displaySmiley() {
  // draw face
  tft.fillScreen(ST77XX_BLACK);
  tft.fillCircle(120, 120, 50, ST77XX_YELLOW);

  // draw mouth
  tft.fillCircle(130, 120, 30, ST77XX_BLACK);  // Swap X and Y coordinates and adjust
  tft.fillRect(85, 90, 45, 65, ST77XX_YELLOW);  // Swap X and Y coordinates and adjust

  // loop for blinking eyes
  for (int i = 0; i < 5; ++i) {
    // draw eyes
    tft.fillCircle(110, 100, 10, ST77XX_BLACK);  // Swap X and Y coordinates
    tft.fillCircle(110, 140, 10, ST77XX_BLACK);  // Swap X and Y coordinates and adjust

    delay(500); // adjust the delay time to control the blinking speed

    // clear eyes
    tft.fillCircle(110, 100, 10, ST77XX_YELLOW);  // Swap X and Y coordinates
    tft.fillCircle(110, 140, 10, ST77XX_YELLOW);  // Swap X and Y coordinates and adjust

    delay(500); // adjust the delay time to control the blinking speed
  }
  
  tft.fillCircle(110, 100, 10, ST77XX_BLACK);  // Swap X and Y coordinates
  tft.fillCircle(110, 140, 10, ST77XX_BLACK);  // Swap X and Y coordinates and adjust
  
}

void displaySady() {
  // draw face
  tft.fillScreen(ST77XX_BLACK);
  tft.fillCircle(120, 120, 50, ST77XX_YELLOW);

  // draw mouth
  tft.fillCircle(145, 120, 20, ST77XX_BLACK);  // Swap X and Y coordinates and adjust
  tft.fillCircle(145, 120, 10, ST77XX_YELLOW);  // Swap X and Y coordinates and adjust
  tft.fillRect(145, 100, 22.5, 41, ST77XX_YELLOW);  // Swap X and Y coordinates and adjust



  // loop for blinking eyes
  for (int i = 0; i < 5; ++i) {
    // draw eyes
    tft.fillCircle(110, 100, 10, ST77XX_BLACK);  // Swap X and Y coordinates
    tft.fillCircle(110, 140, 10, ST77XX_BLACK);  // Swap X and Y coordinates and adjust

    delay(500); // adjust the delay time to control the blinking speed

    // clear eyes
    tft.fillCircle(110, 100, 10, ST77XX_YELLOW);  // Swap X and Y coordinates
    tft.fillCircle(110, 140, 10, ST77XX_YELLOW);  // Swap X and Y coordinates and adjust

    delay(500); // adjust the delay time to control the blinking speed
  }
  
  tft.fillCircle(110, 100, 10, ST77XX_BLACK);  // Swap X and Y coordinates
  tft.fillCircle(110, 140, 10, ST77XX_BLACK);  // Swap X and Y coordinates and adjust
  
}

void displayHearty() {
  // draw heart
  tft.fillScreen(ST77XX_BLACK);

  // draw triangle for the top part of the heart
  tft.fillTriangle(170, 120, 110, 70, 110, 170, ST77XX_RED);

  // draw left half of heart using a circle
  tft.fillCircle(100, 100, 30, ST77XX_RED);

  // draw right half of heart using a circle
  tft.fillCircle(100, 140, 30, ST77XX_RED);
  
  for (int i = 0; i < 3; ++i) {
      tft.fillTriangle(170, 120, 110, 70, 110, 170, ST77XX_BLACK);

      // draw left half of heart using a circle
      tft.fillCircle(100, 100, 30, ST77XX_BLACK);
    
      // draw right half of heart using a circle
      tft.fillCircle(100, 140, 30, ST77XX_BLACK);
    
        delay(50); // adjust the delay time to control the blinking speed
    
      tft.fillTriangle(170, 120, 110, 70, 110, 170, ST77XX_RED);

      // draw left half of heart using a circle
      tft.fillCircle(100, 100, 30, ST77XX_RED);
    
      // draw right half of heart using a circle
      tft.fillCircle(100, 140, 30, ST77XX_RED);
      
        delay(50); // adjust the delay time to control the blinking speed
      }

  // draw left half of heart using a circle
  tft.fillCircle(100, 100, 30, ST77XX_RED);  
  
  // draw triangle for the bottom part of the heart
  tft.fillTriangle(170, 120, 110, 70, 110, 170, ST77XX_RED);

  // draw right half of heart using a circle
  tft.fillCircle(100, 140, 30, ST77XX_RED);
  
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0