/**
First demo for FT6206 Capactive Touch Screen on Wokwi. Enjoy!
https://wokwi.com/arduino/projects/311598148845830720
*/
/***************************************************
This is our touchscreen painting example for the Adafruit ILI9341
captouch shield
----> http://www.adafruit.com/products/1947
Check out the links above for our tutorials and wiring diagrams
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_GFX.h> // Core graphics library
#include <SPI.h> // this is needed for display
#include <Adafruit_ILI9341.h>
#include <Wire.h> // this is needed for FT6206
// The display also uses hardware SPI, plus #9 & #10
#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define EYE_Cx 120
#define EYE_Cy 180
#define EYE_W 160
#define EYE_H 100
#define blink_time 1000
#define X_max 240
void setup(void) {
while (!Serial); // used for leonardo debugging
Serial.begin(115200);
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.fillRoundRect(EYE_Cx - EYE_W/2, EYE_Cy - EYE_H/10, EYE_W, EYE_H/5, 10, ILI9341_WHITE);
delay(1000);
tft.fillRect(EYE_Cx - EYE_W/2, EYE_Cy - EYE_H/2, EYE_W, EYE_H, ILI9341_WHITE);
delay(2000);
}
void loop() {
int xl_curr = EYE_Cx - EYE_W/2;
int cycle = rand()%3;
delay(1000);
if (cycle == 0) {
int r = rand() % 2;
if (r==0) {
xl_curr = move_right(EYE_Cx+EYE_W/2, X_max);
blink(xl_curr);
delay(100);
xl_curr = move_left(X_max - EYE_W, EYE_Cx-EYE_W/2);
delay(100);
xl_curr = move_left(EYE_Cx-EYE_W/2, 0);
delay(100);
xl_curr = move_right(EYE_W/2, EYE_Cx+EYE_W/2);
}
else if (r==1) {
xl_curr = move_right(EYE_Cx+EYE_W/2, X_max);
delay(100);
xl_curr = move_left(X_max - EYE_W, EYE_Cx-EYE_W/2);
delay(100);
xl_curr = move_left(EYE_Cx-EYE_W/2, 0);
delay(100);
blink(xl_curr);
xl_curr = move_right(EYE_W/2, EYE_Cx+EYE_W/2);
}
}
else if (cycle == 1) {
blink(xl_curr);
delay(200);
blink(xl_curr);
}
else{
delay(3000);
}
}
int move_right(int xr_init, int xr_fin){
int num = (int)(15*abs(xr_fin - xr_init)/40);
int dx = (int)((xr_fin - xr_init)/num);
int xleft = xr_init - EYE_W - 13;
int xright = xr_init - 13;
while (xright <= xr_fin - 2)
{
tft.fillRect(xleft, EYE_Cy - EYE_H/2, dx, EYE_H, ILI9341_BLACK);
tft.fillRect(xright, EYE_Cy - EYE_H/2, dx, EYE_H, ILI9341_WHITE);
xleft = xleft + dx;
xright = xright + dx;
delay(15);
}
return(xleft);
}
int move_left(int xl_init, int xl_fin){
int num = (int)(15*abs(xl_fin - xl_init)/40);
int dx = (int)((xl_fin - xl_init)/num);
int xleft = xl_init + 13;
int xright = xl_init + EYE_W + 13;
while (xleft >= xl_fin+2)
{
tft.fillRect(xleft, EYE_Cy - EYE_H/2, dx, EYE_H, ILI9341_WHITE);
tft.fillRect(xright, EYE_Cy - EYE_H/2, dx, EYE_H, ILI9341_BLACK);
xleft = xleft + dx;
xright = xright + dx;
delay(15);
}
return(xleft);
}
void blink(int xl){
delay(100);
tft.fillRect(xl-1, EYE_Cy - EYE_H/2, EYE_W+2, EYE_H, ILI9341_BLACK);
delay(50);
tft.fillRoundRect(xl, EYE_Cy - EYE_H/10, EYE_W, EYE_H/5, 10, ILI9341_WHITE);
delay(blink_time/3);
tft.fillRect(xl, EYE_Cy - EYE_H/2, EYE_W, EYE_H, ILI9341_WHITE);
delay(blink_time*1.5);
}*/
#include <SPI.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <SPI.h> // this is needed for display
#include <Adafruit_ILI9341.h>
#include <Wire.h> // this is needed for FT6206
#include "eye.h"
#define TFT_CS 10
#define TFT_DC 9
#define frames 8
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
/*void setup() {
// put your setup code here, to run once:
while (!Serial); // used for leonardo debugging
Serial.begin(115200);
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_WHITE);
delay(2000);
}*/
void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_WHITE);
delay(1000);
// Draw the eye bitmap on the TFT screen
displayBitmap(eye, EYE_WIDTH, EYE_HEIGHT);
}
void loop() {
// Do nothing in the loop for now
}
// Function to display a bitmap on the screen
void displayBitmap(const uint8_t *bitmap, uint8_t width, uint8_t height) {
tft.startWrite(); // Begin fast write
tft.setAddrWindow(0, 0, width, height); // Set window size
for (uint16_t i = 0; i < width * height; i++) {
tft.pushColor(pgm_read_word(&bitmap[i])); // Read and push pixel data
}
tft.endWrite(); // End fast write
}
/*void loop() {
// put your main code here, to run repeatedly:
for(int i=0;i<frames;i++)
{
delay(40);
}
return;
}*/