Ok, I know, this is kinda silly, but what is .map from the TouchScreen Library?
p.x = map(p.x, TS_LEFT, TS_RT, 0, tft.width());
p.y = map(p.y, TS_TOP, TS_BOT, 0, tft.width());
That is the code that I want to know what it does.
What values does it return and how can I use those values?
I am trying to make a paint program with MCUFRIEND.kbv
This is my entire code, if it's needed:
#include <TouchScreen.h>
#include <MCUFRIEND_kbv.h>
#include <Adafruit_GFX.h>
const int XP = 8, XM = A2, YP = A3, YM = 9; //320x480 ID=0x9486
const int TS_LEFT = 138, TS_RT = 911, TS_TOP = 929, TS_BOT = 145;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
MCUFRIEND_kbv tft;
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
int pixel_x, pixel_y;
void setup() {
Serial.begin(9600);
}
void loop() {
TSPoint p = ts.getPoint();
if (p.z > ts.pressureThreshhold) {
p.x = map(p.x, TS_LEFT, TS_RT, 0, tft.width());
p.y = map(p.y, TS_TOP, TS_BOT, 0, tft.width());
tft.drawCircle(p.x, p.y, 5, BLACK);
Serial.print("\nX:");
Serial.print(p.x);
Serial.print("\tY:");
Serial.print(p.y);
}}
Thanks in Advance!