here is the code for the arduino, the touchscreen has its own processor that talks over ttl serial to the arduino
the arduino takes the output from the screen to the DS io pins
Code:
#include <Wire.h>
#include <AFSoftSerial.h>
#define rxPin 3
#define txPin 2
AFSoftSerial touchscreen = AFSoftSerial(rxPin, txPin);
byte ch1 = 0x28;
byte ch2 = 0x29;
byte pot1 = 0xA9;
byte pot2 = 0xAA;
int stopPin = 4, newData = 5, validRx = 6;
void setup()
{
pinMode(rxPin, INPUT);//set recieve as an input
pinMode(txPin, OUTPUT);//set transmit as an output
pinMode(stopPin, OUTPUT);
pinMode(newData, OUTPUT);
pinMode(validRx, INPUT);
touchscreen.begin(9600);
Wire.begin(); // join i2c bus (address optional for master)
}
int points = 0;
bool stop = false;
void loop()
{
int x = 0, y = 0;
boolean recieved = digitalRead(validRx);
boolean changePoint = touchscreen.available() >= 2
&& (recieved || points == 0)
&& !stop;
if(stop){
digitalWrite(newData, LOW);
digitalWrite(stopPin, HIGH);
}
if(recieved){
digitalWrite(newData, LOW);
delay(100);
}
if(changePoint)
{
x = touchscreen.read();
y = touchscreen.read();
if(touchscreen.available() == 1 && touchscreen.read() == 's')
stop = true;
points++;
if(points >= 50)
stop = true;
writePot(ch1, pot1, x * 2);
writePot(ch1, pot2, y * 2); //
writePot(ch2, pot1, points * 5); // point num
digitalWrite(newData, HIGH);
}
}
void writePot(int chip, int pot, int val)
{
Wire.beginTransmission(chip); // transmit to device 0x28)
Wire.send(pot); // sends instruction byte,
// write to potentiometer-0
Wire.send(val); // sends potentiometer value byte
Wire.endTransmission(); // stop transmitting
}