Salute with TFT display and Arduino Uno

Preview for this project video

Hi everyone!

In this lesson i will tell you, how to make an interesting project with Arduino — holiday salute on a color TFT display with 1.8″ diagonal, controller ST7735.

Copy the sketch for this project. Paste this sketch in a new project file in Arduino IDE, save it with INO extension, load to your board. You can use every board with at least one SPI interface. For example, the most popular boards — Arduino Uno, Nano, Mega, ESP8266 Wemos D1 Mini and others.

Yoг do not need to add any libraries — libraries for TFT and SPI are already built in the IDE.

Sketch for Arduino IDE in C++:

#include <TFT.h>  // Connecting library for TFT
#include <SPI.h>  // Connecting library for SPI

// Settings for screen, pin definicions
#define CS 10
#define DC 9
#define RST 8

// Buzzer pin. Buzzer is not important, you can not connect it
#define BUZZ 3

TFT myScreen = TFT(CS, DC, RST); // Creating display object

// Colors variables
int R;
int G;
int B;

void setup() {
  pinMode(BUZZ, OUTPUT);
  
  // Initing screen
  myScreen.begin();
  myScreen.background(0, 0, 0); // Black background
}

void loop() {
  // Start salute animation
  for (int i = 0; i < 10; i++) {  // 10 times of salute
    drawFirework(random(20, 108), random(20, 80)); // Random coordinates and color
    delay(500); // Pause behind times
  }
  myScreen.background(0, 0, 0); // Clean the display
  delay(1000); // Pause before repeating
}

// Function for drawing salute
void drawFirework(int x, int y) {
  // Generating color RGB
  R = random(0, 255);
  G = random(0, 255);
  B = random(0, 255);
  
  // Flight
  for (int flight = 128; flight > y; flight = flight - 10){
    myScreen.fill(R, G, B);
    myScreen.stroke(R, G, B);
    myScreen.circle(x, flight, 2);
    delay(1);
    myScreen.background(0, 0, 0);
  }
  
  // BOOM sound =)
  tone(BUZZ, 100, 100);
  
  // The BOOM
  for (int r = 1; r < random(30, 40); r++) {
    R = R - 10;
    G = G - 10;
    B = B - 10;
    myScreen.stroke(R, G, B);
    myScreen.noFill();
    myScreen.circle(x, y, r); // Drawing cirlce
    delay(10);
  }

  // Black dots
  myScreen.fill(0, 0, 0);
  for (int i = 0; i < 400; i++) {
    int px = x + random(-40, 40);
    int py = y + random(-40, 40);
    int px2 = x + random(-40, 40);
    int py2 = y + random(-40, 128);
    myScreen.stroke(0, 0, 0);
    myScreen.circle(px, py, 1); // Drawing random dots
    myScreen.stroke(55, 155, 255);
    myScreen.circle(px2, py2, 1); // Drawing random dots
  }
  delay(100);
  // Clean display
  myScreen.background(0, 0, 0);
}

Connecting scheme:

If you connect zummer, so connecting scheme is this:

Project if verified, video demonstation:

You can support author on Rutube on button «Support».

Thank you very much =)

5/5 - (1 голос)


Поделись!