#include <Arduino.h>
//#include <structs.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 <Adafruit_FT6206.h>
#include <Fonts/FreeMonoBoldOblique12pt7b.h>
#include <Fonts/FreeSerif9pt7b.h>
#include <Fonts/FreeMono9pt7b.h>
//from adafruit_button import Button
/*
Home Screen
Buttons
Measure (This screen)
Text showing force
Text showing Distance
Text Showing Load Cell Calibration Number
Set Tare (This screen)
Set Zero Distance
Enter Calibration # -> Goto Enter Calibration# Screen
Calibrate -> Goto Calibrate screen
Calibrate Screen
Return
Enter Calibration # -> Goto Enter Calibration# Screen
Step buttons/text:
1. Tare... remove any weights from the scale.
When ready, press the yellow button to set Tare
2. Tare Done...Place a known weight on the scale and press
Enter Weight:
Text input for known weight
Button ..Calculate Load Cell Constant
3. Result:
Text for displaying constant
Button: Save
Button: Restart Calibration
Enter Calibration Number Screen
Input for Calibration#
Save Button
Return Button
Text with Current Calibration Number
*/
// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_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);
int currentScreenIdx = 0;
uint16_t bttnTxT_X(
uint16_t rectW,
uint16_t strgLngth
)
{
return ((rectW-8*strgLngth)/2);
};
uint16_t bttnTxT_Y(
uint16_t rectH,
uint16_t strgSize,
uint16_t line,
uint16_t of
)
{
if (of==1) {
return (rectH-strgSize*10)/2+10;
} else if(of==2){
if(line==1){
return (rectH-strgSize*10)/2;
} else if(line==2){
return 2*(rectH-strgSize*10)/2;
}
}
return 0;
};
class BtnClass {
public:
BtnClass(
bool latching,
uint16_t X,
uint16_t Y,
uint16_t L,
uint16_t W,
uint16_t BGColor,
uint16_t FntColor,
uint16_t FntSize
);
void ClickMe(uint16_t X, uint16_t Y);
void DrawBttn(String txtLine1, String txtLine2);
private:
bool _latching;
uint16_t _X;
uint16_t _Y;
uint16_t _L;
uint16_t _W;
uint16_t _BGColor;
uint16_t _FntColor;
uint16_t _FntSize;
};
BtnClass::BtnClass(
bool latching,
uint16_t X,
uint16_t Y,
uint16_t L,
uint16_t W,
uint16_t BGColor,
uint16_t FntColor,
uint16_t FntSize
){
_latching = latching;
_X = X;
_Y = Y;
_L = L;
_W = W;
_BGColor = BGColor;
_FntColor = FntColor;
_FntSize = FntSize;
};
void BtnClass::ClickMe(uint16_t X, uint16_t Y)
{
};
void BtnClass::DrawBttn(String txtLine1, String txtLine2)
{
tft.fillRoundRect(
&this->_X,
&this->_Y,
&this->_L,
&this->_W,
2,
&this->_BGColor
);
tft.fillRoundRect(_X, _Y, _L, _W, 2, _BGColor);
//Serial.println(txtLine2.length());
tft.setTextSize(_FntSize);
tft.setTextColor(_FntColor);
if(txtLine2.length()>0){
tft.setCursor(_X+bttnTxT_X(_L, txtLine1.length()), _Y + bttnTxT_Y(_W, _FntSize, 1, 2));
tft.print(txtLine1);
tft.setCursor(_X+bttnTxT_X(_L, txtLine2.length()), _Y + bttnTxT_Y(_W, _FntSize, 2, 2));
tft.print(txtLine2);
} else {
tft.setCursor(_X+bttnTxT_X(_L, txtLine1.length()), _Y + bttnTxT_Y(_W, _FntSize, 1, 1));
Serial.println(bttnTxT_X(_L, txtLine1.length()));
tft.print(txtLine1);
};
};
BtnClass measureBTN(
false,
0,
35,
100,
40,
ILI9341_BLUE,
ILI9341_YELLOW,
1
);
BtnClass ftareBTN(
false,
0,
85,
100,
40,
ILI9341_BLUE,
ILI9341_YELLOW,
1
);
BtnClass dtareBTN(
false,
0,
135,
100,
40,
ILI9341_BLUE,
ILI9341_YELLOW,
1
);
BtnClass calibBTN(
false,
0,
185,
100,
40,
ILI9341_BLUE,
ILI9341_YELLOW,
1
);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
//Serial.println(F("Cap Touch Paint!"));
tft.begin();
tft.setRotation(1);
if (! ctp.begin(40)) { // pass in 'sensitivity' coefficient
Serial.println("Couldn't start FT6206 touchscreen controller");
while (1);
}
Serial.println("Capacitive touchscreen started");
tft.setFont(&FreeSerif9pt7b);
tft.cp437(true);
drawHome();
}
void loop() {
// Wait for a touch
if (! ctp.touched()) {
return;
}
// Retrieve a point
TS_Point p = ctp.getPoint();
/*
// Print out raw data from screen touch controller
Serial.print("X = "); Serial.print(p.x);
Serial.print("\tY = "); Serial.print(p.y);
Serial.print(" -> ");
*/
// flip it around to match the screen.
/*
map(value, fromLow, fromHigh, toLow, toHigh)
value: the number to map.
fromLow: the lower bound of the value’s current range.
fromHigh: the upper bound of the value’s current range.
toLow: the lower bound of the value’s target range.
toHigh: the upper bound of the value’s target range.
*/
p.x = map(p.x, 0, 240, 240, 0);
//p.y = map(p.y, 0, 1, 0, 1);
// Print out the remapped (rotated) coordinates
/*Serial.print("("); Serial.print(p.x);
Serial.print(", "); Serial.print(p.y);
Serial.println(")");*/
tft.fillCircle(p.y, p.x, 3, ILI9341_YELLOW);
//tft.
}
void drawHome(){
/*
Home Screen
Buttons
Measure (This screen)
Text showing force
Text showing Distance
Line graph?
Text Showing Load Cell Calibration Number
Set Tare (This screen)
Set Zero Distance
Calibrate -> Goto Calibrate screen
*/
tft.fillScreen(ILI9341_BLACK);
//Adafruit_GFX_Button HMeasBtn, HSetTareBtn, HNavECBtn, HNavCalBtn;
currentScreenIdx = 0;
tft.setTextSize(2);
tft.setTextColor(ILI9341_YELLOW);
tft.setCursor(55, 25);
tft.print("Shock Force");
measureBTN.DrawBttn("Measure", "This");
ftareBTN.DrawBttn("Force", "Tare");
dtareBTN.DrawBttn("Distance", "Tare");
calibBTN.DrawBttn("Calibrate", "");
/*
int16_t x,
int16_t y,
uint16_t w,
uint16_t h,
uint16_t outline,
uint16_t fill,
uint16_t textcolor,
char * label,
uint8_t textsize
HMeasBtn.initButton(&tft, 100, 100, 100, 50, ILI9341_YELLOW, ILI9341_YELLOW, ILI9341_BLUE, "Enter Calibration Number", 1);
HMeasBtn.drawButton(true);
*/
/*
tft.fillRoundRect(0, 40, 100, 40, 2, ILI9341_BLUE);
tft.setTextSize(1);
tft.setCursor(15, 55);
tft.print("Load Cell");
tft.setCursor(10, 75);
tft.print("Calibration");
*/
//tft.fillRoundRect(130, 40, 100, 40, 2, ILI9341_BLUE);
//tft.fillRoundRect(10, 100, 100, 40, 2, ILI9341_BLUE);
//tft.fillRoundRect(130, 100, 100, 40, 2, ILI9341_BLUE);
};
Loading
ili9341-cap-touch
ili9341-cap-touch