Instantly share code, notes, and snippets.

Embed
What would you like to do?
int y1 = A0;
int x2 = A1;
int y2 = A2;
int x1 = A3;
int ledPin0 = 2;
int ledPin1 = 3;
int ledPin2 = 4;
int ledPin3 = 5;
void setup() {
Serial.begin(9600);
pinMode(ledPin0, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
//pinMode(ledPin0, OUTPUT);
int readX() {
pinMode(y1, INPUT);
pinMode(x2, OUTPUT);
pinMode(y2, INPUT);
pinMode(x1, OUTPUT);
digitalWrite(x2, LOW);
digitalWrite(x1, HIGH);
delay(5); //pause to allow lines to power up
return analogRead(y1);
}
int readY() {
pinMode(y1, OUTPUT);
pinMode(x2, INPUT);
pinMode(y2, OUTPUT);
pinMode(x1, INPUT);
digitalWrite(y1, LOW);
digitalWrite(y2, HIGH);
delay(5); //pause to allow lines to power up
return analogRead(x2);
}
void loop()
int x = readX();
int y = readY();
if (y > 510 && x > 520 && x < 940 && y < 940)
{
Serial.println("a");
Serial.println(y);
digitalWrite(ledPin0, LOW);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
}
else if (y > 510 && x < 510)
{
Serial.println("b");
digitalWrite(ledPin0, HIGH);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
}
else if (y < 500 && x > 520)
{
Serial.println("c");
digitalWrite(ledPin0, HIGH);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
}
else if (y < 500 && x < 510)
{
Serial.println("d");
digitalWrite(ledPin0, HIGH);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, LOW);
}
else if (x > 1000 && y > 1000)
{
Serial.println("NOOOOOOONE");
}
delay(100); //just to slow this down so it is earier to read in the terminal - Remove if wanted
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment