Advertisement
Guest User

Untitled

a guest
Dec 9th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. void setup()
  2. {
  3. Serial.begin(9600);
  4. }
  5.  
  6. int readX() // returns the value of the touch screen's X-axis
  7. {
  8. int xr = 0;
  9. pinMode(14, INPUT); // A0
  10. pinMode(15, OUTPUT); // A1
  11. pinMode(16, INPUT); // A2
  12. pinMode(17, OUTPUT); // A3
  13. digitalWrite(15, LOW); // set A1 to GND
  14. digitalWrite(17, HIGH); // set A3 as 5V
  15. delay(5); // short delay is required to give the analog pins time to adjust to their new roles
  16. xr = analogRead(0);
  17. return xr;
  18. }
  19.  
  20. int readY() // returns the value of the touch screen's Y-axis
  21. {
  22. int yr = 0;
  23. pinMode(14, OUTPUT); // A0
  24. pinMode(15, INPUT); // A1
  25. pinMode(16, OUTPUT); // A2
  26. pinMode(17, INPUT); // A3
  27. digitalWrite(14, LOW); // set A0 to GND
  28. digitalWrite(16, HIGH); // set A2 as 5V
  29. delay(5); // short delay is required to give the analog pins time to adjust to their new roles
  30. yr = analogRead(1);
  31. return yr;
  32. }
  33.  
  34. long first = 0;
  35. long second = 0;
  36. int times = 0;
  37. int zoneSelected = 0;
  38. long timeNoFinger = 0;
  39. int index = 0;
  40. void detectCollisionWithScreen()
  41. { x = readX();
  42. y = readY();
  43.  
  44. if (y > 510 && x > 520 && x < 800 && y <800)
  45. {
  46. zoneSelected = 1;
  47. first = millis();
  48. }
  49. else
  50. if (y>510 && x < 510)
  51. {
  52. zoneSelected = 2;
  53. first = millis();
  54. }
  55. else
  56. if (y<500 && x>520)
  57. {
  58. zoneSelected = 3;
  59. first = millis();
  60. }
  61. else
  62. if (y<500 && x<510)
  63. {
  64. zoneSelected = 4;
  65. first = millis();
  66. }
  67. else
  68. if (x>800 && y>800)
  69. {
  70. //this will be called each time a finger is lifted
  71. second = millis();
  72. if(second - first < 300) {
  73. //possible double tap
  74. times++;
  75. second = millis();
  76. first = second;
  77. } else {
  78. times = 0;
  79. second = millis();
  80. first = second;
  81. }
  82.  
  83. if(times%2 == 0) {Serial.println(String(zoneSelected)); times = 0; }
  84. }
  85. }
  86.  
  87.  
  88. void loop()
  89. {
  90. detectCollisionWithScreen();
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement