For my interactive assignment I wanted to create a wearable which would display the users current emotion with as simple user interaction as possible. Originally I intended to use an infrared remote for the user to interact with the device, but that turned into being a problem when the Touch Screen LCD Shield I bought required all the arduino pins. So I decided to use the touch screen interface instead, which allowed for the addition of a “custom” mood in which the user can draw on the display.
Below are 5 pictures of the wearable along with the arduino source code.
#include <Wire.h>
#include <Adafruit_TFTLCD.h>
#include <Adafruit_GFX.h> // Core graphics library
#include “wearable.h”
#include <stdint.h>
#include “TouchScreen.h”
#define WIDTH 320
#define HEIGHT 240
#define STOP_TEXT “FUCK OFF”
#define YIELD_TEXT “STAY BACK”
#define GO_TEXT ” HELLO!”
// Pins for the LCD Shield
#define YP A3 // must be analog
#define XM A2 // must be analog
#define YM 9 // digital or analog pin
#define XP 8 // digital or analog pin
// Calibration mins and max for raw data when touching edges of screen
#define TS_MINX 160
#define TS_MINY 210
#define TS_MAXX 930
#define TS_MAXY 910
#define MINPRESSURE 10
#define MAXPRESSURE 1000
// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we’re using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
int lastX = -1;
void setup()
{
Serial.begin(9600);
Wire.begin();
tft.reset();
tft.begin(tft.readID());
tft.fillScreen(BLACK);
tft.setTextSize(3);
tft.setRotation(1);
tft.setCursor(0, HEIGHT – 30);
tft.setTextColor(RED);
tft.println(“Stop”);
tft.setCursor(WIDTH/4 + 5, HEIGHT – 30);
tft.setTextColor(YELLOW);
tft.println(“Yield”);
tft.setCursor(WIDTH/2 + 30, HEIGHT – 30);
tft.setTextColor(GREEN);
tft.println(“Go”);
tft.setCursor(3*WIDTH/4, HEIGHT – 30);
tft.setTextColor(WHITE);
tft.println(“Draw”);
}
void fillButton (int button, int color) {
tft.fillRect(button*(WIDTH/4), 3*HEIGHT/4, (button+1)*(WIDTH/4), HEIGHT/4, color);
}
void fillScreenExceptButtons (int color) {
tft.fillRect(0, 0, WIDTH, 4*HEIGHT/5, color);
}
void drawCustom () {
fillScreenExceptButtons(BLACK);
while (true) {
TSPoint p = ts.getPoint();
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
if (p.z > MINPRESSURE) {
int mappedX = map(p.y, TS_MINX, TS_MAXX, 0, WIDTH);
int mappedY = map(p.x, TS_MINY, TS_MAXY, 0, HEIGHT);
// if they click on a different button, handle that
if (HEIGHT – mappedY >= 192) {
// if clicked on draw button, wipe screen and continue
int button = map(p.y, TS_MINY, TS_MAXY, 0, 4);
if (button == 0) fillScreenExceptButtons(BLACK);
else return;
}
else {
tft.drawPixel(WIDTH – mappedX, HEIGHT – mappedY, WHITE);
}
}
}
}
void loop()
{
TSPoint p = ts.getPoint();
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
int mappedX = map(p.y, TS_MINX, TS_MAXX, 0, 4);
int mappedY = map(p.x, TS_MINY, TS_MAXY, 0, HEIGHT);
if (HEIGHT – mappedY > 192 && p.z > MINPRESSURE && ((mappedX != lastX) || mappedX == 0)) {
lastX = mappedX;
tft.setTextColor(BLACK);
tft.setTextSize(6);
tft.setCursor(20, 70);
switch (mappedX) {
case 0: drawCustom();
break;
case 1: fillScreenExceptButtons(GREEN);
tft.println(GO_TEXT);
break;
case 2: tft.setTextSize(5);
fillScreenExceptButtons(YELLOW);
tft.println(YIELD_TEXT);
break;
case 3: fillScreenExceptButtons(RED);
tft.println(STOP_TEXT);
break;
default: fillScreenExceptButtons(BLUE);
break;
}
Serial.println(mappedX);
}
}