Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Mechatronics LAB
Published © MIT

Basic Touch Screen– Arduino Workshop

For this project, We know about Basic Touch Screen Arduino and you will need a Nintendo DS touch screen as well as a breakout module.

BeginnerFull instructions provided1 hour2,367
Basic Touch Screen– Arduino Workshop

Things used in this project

Hardware components

Resistors
×1
Touch screen breakout
×1
connecting wire
×1
Breadboard
×1
Arduino uno
×1

Story

Read more

Schematics

Basic Touch Screen– Arduino Workshop

Code

Code snippet #1

Arduino
// Power connections
#define Left 8 // Left (X1) to digital pin 8
#define Bottom 9 // Bottom (Y2) to digital pin 9
#define Right 10 // Right (X2) to digital pin 10
#define Top 11 // Top (Y1) to digital pin 11

// Analog connections
#define topInput A0 // Top (Y1) to analog pin A0
#define rightInput A1 // Right (X2) to analog pin A1

int coordX = 0, coordY = 0;

void setup() {
  Serial.begin(38400);
}

void loop() {
  if (touch()) { // If screen touched, print coordinates
    Serial.print(coordX);
    Serial.print(" ");
    Serial.println(coordY);
    delay(250);
  }
}

boolean touch() {
  boolean touch = false;

  // Get horizontal coordinates
  pinMode(Top, INPUT); // Top and Bottom to high impedance
  pinMode(Bottom, INPUT);
  pinMode(Left, OUTPUT);
  digitalWrite(Left, LOW); // Set Left to low
  pinMode(Right, OUTPUT); // Set Right to +5V
  digitalWrite(Right, HIGH);
  delay(3);
  coordX = analogRead(topInput);

  // Get vertical coordinates
  pinMode(Right, INPUT); // Left and Right to high impedance
  pinMode(Left, INPUT);
  pinMode(Bottom, OUTPUT); // Set Bottom to Gnd
  digitalWrite(Bottom, LOW);
  pinMode(Top, OUTPUT); // Set Top to +5V
  digitalWrite(Top, HIGH);
  delay(3);
  coordY = analogRead(rightInput);

  // Check if the screen has been touched
  if (coordX < 1000 && coordX > 24 && coordY < 1000 && coordY > 24) {
    touch = true;
  }
  return touch;
}

Credits

Mechatronics LAB
75 projects • 48 followers
I am Sarful , I am a Mechatronics Engineer & also a teacher I am Interested in the evolution of technology in the automation industry .
Contact

Comments

Please log in or sign up to comment.