The code below draws a sine wave on the Adafruit 3.5" TFT 32x480 display using the adafruit GFX lib. I need to determine the pixel color at x, y as shown at the bottom of the script (Slide function). The line "Serial.println(tft.getPixel(100, 100);" generates an error because the GFX library apparently doesn't contain a getPixel function the user can use.
So how does one get the color of a pixel on the screen?
// for teensy 4.0
/***************************************************************************************************************/
#include <arduino.h>
#include "Adafruit_HX8357.h" // the 480x320 display
#include <Adafruit_GFX.h> // Core graphics library
// The display uses hardware SPI, plus pins 9 & 10
#define TFT_DC_PIN 9
#define TFT_CS_PIN 10
#define TFT_RST_PIN 15 // tie this to arduino RST if you like
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS_PIN, TFT_DC_PIN, TFT_RST_PIN);
// Colors
#define BACKGROUND 0xA514
#define FILL 0xAD75
#define BLACK 0x0000
#define BLUE 0x0019
#define YELLOW 0xFFE0
#define RED 0xA800
#define GREEN 0x0360
#define WHITE 0xFFFF
#define GRAY 0x9CD3
const float rad_per_deg = 0.01745329251; // value of a radian per degree
float theta = 0;
int pulse_width_sin = 0;
int pulse_width_cos = 0;
int sign = 1; // to control the increments or decrements of angle parameter
int h, v;
/***************************************************************************************************************/
void setup(void)
{
Serial.begin(115200);
delay(250);
tft.begin();
delay(200);
tft.setRotation(1);
tft.fillScreen(BLACK);
}
/***************************************************************************************************************/
void loop(void)
{
Sine();
}
void Sine()
{
if (theta == 3.14159265359) sign = -1; // keep increasing the value of theta till pi and then decrease till zero
else if (theta == 0) sign = 1;
theta = theta + (rad_per_deg * sign);
pulse_width_sin = 255 * sin(theta);
pulse_width_cos = 255 * cos(theta);
v = 160 + pulse_width_sin / 2;
h += 1;
if (h > 478)
h = 0;
tft.drawLine(h, v, h, v + 1, 0x07e0);
pulse_width_sin = abs(pulse_width_sin);
pulse_width_cos = abs(pulse_width_cos);
delay(10); // control the frequency here
}
void Slide()
{
// Serial.println(tft.getPixel(100, 100);
}
`