So this took me longer to put together than expected as various events in my life have kept me very busy, in a good way. I also had trouble with the tool Fritzing. It is the tool I used in Part 1 of this tutorial to create the image of the breadboard and Arduino laid out nicely. I had trouble building my own Nintendo DS Touchscreen Connector and the Touchscreen itself. There were Spark Fun equals but they were not exactly the same and I didn’t want to confuse anybody by accident.
Due to this tutorial taking too long I’m just going to show a few images of the device along with the code. I apologize the lack of a proper tutorial.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
#include "TouchScreen.h" #define RED 11 #define GREEN 10 #define BLUE 9 int y1 = A0; int x2 = A1; int y2 = 7; int x1 = 6; TouchScreen ts = TouchScreen(x1, y1, x2, y2, 10000); void setup() { pinMode(RED, OUTPUT); pinMode(GREEN, OUTPUT); pinMode(BLUE, OUTPUT); } float clamp(float value) { value *= 255.0f; if (value > 255.0f) value = 255.0f; else if (value < 0.0f) value = 0.0f; return 255.0f - value; } void loop() { Point touchedPoint = ts.getPoint(); if (touchedPoint.z > ts.pressureThreshhold) { float X = touchedPoint.x / 1023.0f; float Y = touchedPoint.y / 1023.0f; float Z = 1.0f - x - y; float r = X * 1.4628067f - Y * 0.1840623f - Z * 0.2743606f; float g = -X * 0.5217933f + Y * 1.4472381f + Z * 0.0677227f; float b = X * 0.0349342f - Y * 0.0968930f + Z * 1.2884099f; r = r <= 0.0031308f ? 12.92f * r : (1.0f + 0.055f) * pow(r, (1.0f / 2.4f)) - 0.055f; g = g <= 0.0031308f ? 12.92f * g : (1.0f + 0.055f) * pow(g, (1.0f / 2.4f)) - 0.055f; b = b <= 0.0031308f ? 12.92f * b : (1.0f + 0.055f) * pow(b, (1.0f / 2.4f)) - 0.055f; r = clamp(r); g = clamp(g); b = clamp(b); analogWrite(RED, r); analogWrite(GREEN, g); analogWrite(BLUE, b); } delay(100); } |