Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup()
- {
- Serial.begin(9600);
- }
- int x,y = 0;
- int readX() // returns the value of the touch screen's X-axis
- {
- int xr = 0;
- pinMode(14, INPUT); // A0
- pinMode(15, OUTPUT); // A1
- pinMode(16, INPUT); // A2
- pinMode(17, OUTPUT); // A3
- digitalWrite(15, LOW); // set A1 to GND
- digitalWrite(17, HIGH); // set A3 as 5V
- delay(5); // short delay is required to give the analog pins time to adjust to their new roles
- xr = analogRead(0);
- return xr;
- }
- int readY() // returns the value of the touch screen's Y-axis
- {
- int yr = 0;
- pinMode(14, OUTPUT); // A0
- pinMode(15, INPUT); // A1
- pinMode(16, OUTPUT); // A2
- pinMode(17, INPUT); // A3
- digitalWrite(14, LOW); // set A0 to GND
- digitalWrite(16, HIGH); // set A2 as 5V
- delay(5); // short delay is required to give the analog pins time to adjust to their new roles
- yr = analogRead(1);
- return yr;
- }
- long first = 0;
- long second = 0;
- int times = 0;
- int zoneSelected = 0;
- long timeNoFinger = 0;
- int index = 0;
- void detectCollisionWithScreen()
- { x = readX();
- y = readY();
- if (y > 510 && x > 520 && x < 800 && y <800)
- {
- zoneSelected = 1;
- first = millis();
- }
- else
- if (y>510 && x < 510)
- {
- zoneSelected = 2;
- first = millis();
- }
- else
- if (y<500 && x>520)
- {
- zoneSelected = 3;
- first = millis();
- }
- else
- if (y<500 && x<510)
- {
- zoneSelected = 4;
- first = millis();
- }
- else
- if (x>800 && y>800)
- {
- //this will be called each time a finger is lifted
- second = millis();
- if(second - first < 300) {
- //possible double tap
- times++;
- second = millis();
- first = second;
- } else {
- times = 0;
- second = millis();
- first = second;
- }
- if(times%2 == 0) {Serial.println(String(zoneSelected)); times = 0; }
- }
- }
- void loop()
- {
- detectCollisionWithScreen();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement