Hi guys,
I am really excited to share my project here with a hope to learn from the more experienced among you!
Lets keep this short and sweet.
I used to hate electronics and I had zilch experience, after I did an k20 supercharged engine swap I discovered it may not be too bad, I then decided to jump in and get an DFRobot starter kit and a few evening later I find myself here.
My project is to create an automotive heating and air conditioning controller using a 2.8" TFT capacitive touch screen. Components so far:
- Arduino Uno R3.
- Adafruit 2.8” TFT Capacitive touch screen.
- Engine coolant temp sensor – yet to be determined.
- Cabin air temp sensor – yet to be determined.
- 4 Pos fan switch (with settable fan speeds) or Pot.
- Pot for heater controller.
- 12v 2-3a DC Fan.
- 12v DC Servo to control cable based water control valve.
- DC Motor Driver. I think this is called a H Bridge?
- 12v Air valves.
My plans are to have your typical automotive HVAC functions operated via buttons on the touch screen, current ideas for control:
• AC On/Off
• Defrost Vents On/Off
• Dash Vents On/Off
• Footwell Vents On/Off
• User Set Cabin Temp – Arduino control over fan, water valve and AC to maintain.
The layout of the touch screen control is to have the buttons at the bottom with the engine coolant and air temps displayed at the top of the screen.
I am still at the very early stages of writing the code but thought now is a good a time as any to show where I am and to seek recommendations on whether I am going in the right direction.
So far I have the button change colour from blue to cyan when pressed, and back to blue when pressed again, unfortunately the button can cycle very quickly registered multiple touches per press, I have researched into a timer to not allow a second press within a certain amount of time with using a delay function, what would be the best way to go about this?
//screen size: 240 x 320px
//orientation: portrait
#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>
// 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
// Size of the menu colour selection boxes
#define RecHeight 60
#define RecLength 105
#define BLACK 0x0000
#define CYAN 0x07FF
#define RED 0xF800
#define BLUE 0x001F
#define WHITE 0xFFFF
#define textsize 4
int ACSELECT = 0;
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup() {
// Serial Touch Setup.
while (!Serial); // used for leonardo debugging
Serial.begin(300);
/*Serial.println(F("Cap Touch Screen")); */
tft.begin();
if (! ctp.begin(40)) { // pass in 'sensitivity' coefficient
Serial.println("Couldn't start FT6206 touchscreen controller");
while (1);
}
Serial.println("Capacitive touchscreen started");
tft.fillScreen(BLACK);
// 1st Box
// tft,fillRect(X position, Y Position, width, height, colour)
tft.fillRect(10, 250, RecLength, RecHeight, BLUE);
//1st Box Text
tft.setCursor(40, 264);
tft.setTextColor(WHITE);
tft.setTextSize(textsize);
tft.print("AC");
// 2nd Box
tft.fillRect(10, 180, RecLength, RecHeight, BLUE);
// 3rd Box
tft.fillRect(125, 250, RecLength, RecHeight, BLUE);
// 4th Box
tft.fillRect(125, 180, RecLength, RecHeight, BLUE);
}
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.
p.x = map(p.x, 0, 240, 240, 0);
p.y = map(p.y, 0, 320, 320, 0);
// Print out the remapped (rotated) coordinates
Serial.print("("); Serial.print(p.x);
Serial.print(", "); Serial.print(p.y);
Serial.println(")");
if (p.y > 250 && p.y < 310 && p.x > 10 && p.x < 115) { // if this area is pressed
if (ACSELECT < 1){
tft.fillRect(10, 250, RecLength, RecHeight, CYAN);
tft.setCursor(40, 264);
tft.setTextColor(WHITE);
tft.setTextSize(textsize);
tft.print("AC");
ACSELECT = 1;
} else if (ACSELECT > 0){
tft.fillRect(10, 250, RecLength, RecHeight, BLUE);
tft.setCursor(40, 264);
tft.setTextColor(WHITE);
tft.setTextSize(textsize);
tft.print("AC");
ACSELECT = 0;
}
}
}