/*
ESP32 + ILI9341 LCD Basic Example
https://wokwi.com/projects/325324981270479442
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
//RPM settings
int xmax=240; // max length x-axis
int ymax=240; // max length y-axis
int xcenter=xmax/2; // center of x-axis
int ycenter=ymax/2; // center of y-axis
int arc=ymax/4;
int p, w, m,a=10; // a= Needle Speed
int xx=0;
int outlineThickness = 3;
void setup() {
tft.begin();
/*
tft.setCursor(20, 120);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("Hello ESP32");
tft.setCursor(24, 160);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.println("I can do SPI :-)");
*/
tft.fillCircle(xcenter, ycenter, arc, ILI9341_GREEN);
tft.fillCircle(xcenter, ycenter, arc-outlineThickness, ILI9341_BLACK);
}
void gauge(uint8_t angle) {
static float x1 = 0.0;
static float y1 = 0.0;
// Draw the Needle
//erase previous line
tft.drawLine(xcenter+(arc-20)*x1, ycenter-(arc-20)*y1, xcenter+(arc-outlineThickness)*x1, ycenter-(arc-outlineThickness)*y1, ILI9341_BLACK);
x1=sin(2*angle*2*3.14/100); // needle position
y1=cos(2*angle*2*3.14/100);
//draw new line
tft.drawLine(xcenter+(arc-20)*x1, ycenter-(arc-20)*y1, xcenter+(arc-outlineThickness)*x1, ycenter-(arc-outlineThickness)*y1, ILI9341_WHITE);
//tft.fillCircle(xcenter, ycenter, arc-20, ILI9341_BLACK);
}
void loop() {
static uint16_t ADC_reading_prev;
uint16_t ADC_reading = analogRead(32);
if(ADC_reading != ADC_reading_prev){
tft.fillRect(0, 0, 200, 40, ILI9341_BLACK);
tft.setCursor(0, 00);
tft.setTextColor(ILI9341_GREEN);
tft.println(ADC_reading);
gauge(ADC_reading/40);
ADC_reading_prev = ADC_reading;
}
delay(10); }