Monday, March 7, 2022

Simple Arduino TFT LCD Robot eyes

I am working on making some better "eyes" for my humanoid robots. The 8x8 LED design was cool but I can do a lot more with an LCD screen.  I need to make it more universal to work with different sizes of screens.


This is a link to the video of this robot head being printed:

Here is the code so far:
// Program for Eyes on a 1.8" TFT LCD Screen

#include <TFT.h>  // Arduino LCD library
#include <SPI.h>
 
// Pins
#define cs   10
#define dc   9
#define rst  8
 
// Create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);
 
void setup() {
 
   // Initialize the screen
   TFTscreen.begin();
 
   // Clear the screen
   TFTscreen.background(0, 0, 0);
 
   // Set font color to white
   TFTscreen.stroke(255,255,255);
 
   // Set the font size
   TFTscreen.setTextSize(2);
 
   // Write some text on the screen
//   TFTscreen.text("Hello World!",0,0);
}
 
void loop() {
   TFTscreen.noStroke();
   // Eyes Center
   TFTscreen.fill(255,255,255);
   TFTscreen.circle(20,60,20);
   TFTscreen.circle(50,60,20); // oblong circle
   TFTscreen.rect(20,40,30,41);
   TFTscreen.fill(255,0,0);
   TFTscreen.circle(35,60,20);
   TFTscreen.fill(0,0,0);
   TFTscreen.circle(35,60,10);

   TFTscreen.fill(255,255,255);
   TFTscreen.circle(110,60,20);
   TFTscreen.circle(140,60,20);// oblong circle
   TFTscreen.rect(110,40,30,41);
   TFTscreen.fill(255,0,0);
   TFTscreen.circle(125,60,20);
   TFTscreen.fill(0,0,0);
   TFTscreen.circle(125,60,10);
   delay(1000);

   // Eyes Narrow
   TFTscreen.fill(0,0,0);
   TFTscreen.rect(0,40,160,10);
   TFTscreen.rect(0,70,160,11);
   delay(1000);
   
   // Eyes Big
   TFTscreen.fill(255,255,255);
   TFTscreen.circle(30,60,30);
   TFTscreen.circle(40,60,30); // oblong circle
   TFTscreen.rect(20,40,30,41);
   TFTscreen.fill(255,0,0);
   TFTscreen.circle(35,60,20);
   TFTscreen.fill(0,0,0);
   TFTscreen.circle(35,60,10);

   TFTscreen.fill(255,255,255);
   TFTscreen.circle(120,60,30);
   TFTscreen.circle(130,60,30);// oblong circle
   TFTscreen.rect(110,40,30,41);
   TFTscreen.fill(255,0,0);
   TFTscreen.circle(125,60,20);
   TFTscreen.fill(0,0,0);
   TFTscreen.circle(125,60,10);
   delay(1000);
   TFTscreen.fill(0,0,0);
   TFTscreen.rect(0,30,160,61); // Erase eyes


   // Eyes Right
   TFTscreen.fill(255,255,255);
   TFTscreen.circle(20,60,20);
   TFTscreen.circle(50,60,20); // oblong circle
   TFTscreen.rect(20,40,30,41);
   TFTscreen.fill(255,0,0);
   TFTscreen.circle(20,60,20);
   TFTscreen.fill(0,0,0);
   TFTscreen.circle(20,60,10);

   TFTscreen.fill(255,255,255);
   TFTscreen.circle(110,60,20);
   TFTscreen.circle(140,60,20);// oblong circle
   TFTscreen.rect(110,40,30,41);
   TFTscreen.fill(255,0,0);
   TFTscreen.circle(110,60,20);
   TFTscreen.fill(0,0,0);
   TFTscreen.circle(110,60,10);
   delay(1000);
   
   // Eyes Left
   TFTscreen.fill(255,255,255);
   TFTscreen.circle(20,60,20);
   TFTscreen.circle(50,60,20); // oblong circle
   TFTscreen.rect(20,40,30,41);
   TFTscreen.fill(255,0,0);
   TFTscreen.circle(50,60,20);
   TFTscreen.fill(0,0,0);
   TFTscreen.circle(50,60,10);

   TFTscreen.fill(255,255,255);
   TFTscreen.circle(110,60,20);
   TFTscreen.circle(140,60,20);// oblong circle
   TFTscreen.rect(110,40,30,41);
   TFTscreen.fill(255,0,0);
   TFTscreen.circle(140,60,20);
   TFTscreen.fill(0,0,0);
   TFTscreen.circle(140,60,10);
   delay(1000);
 
}


No comments: