nitrodog96

tetris controller code final

Jan 23rd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. void setup() {
  2. // put your setup code here, to run once:
  3. Serial.begin(9600);
  4. pinMode(A0, INPUT);
  5. pinMode(A1, INPUT);
  6. pinMode(6, INPUT);
  7. pinMode(7, INPUT);
  8. pinMode(11, OUTPUT);
  9. pinMode(12, OUTPUT);
  10. pinMode(13, OUTPUT);
  11. }
  12.  
  13. void loop() {
  14. // put your main code here, to run repeatedly:
  15. String outputX = "A1 / X: ";
  16. String outputY = "A0 / Y: ";
  17. String outputA = "A Pressed: ";
  18. String outputB = "B Pressed: ";
  19.  
  20. if(analogRead(A1) > 1000)
  21. {
  22. outputX += "Right";
  23. digitalWrite(11, HIGH);
  24. digitalWrite(12, LOW);
  25. }
  26. else if(analogRead(A1) < 100)
  27. {
  28. outputX += "Left";
  29. digitalWrite(11, LOW);
  30. digitalWrite(12, HIGH);
  31. }
  32. else
  33. {
  34. outputX += "Not sensing";
  35. digitalWrite(11, LOW);
  36. digitalWrite(12, LOW);
  37. }
  38.  
  39. if(analogRead(A0) > 1000)
  40. {
  41. outputY += "Up";
  42. }
  43. else if(analogRead(A0) < 100)
  44. {
  45. outputY += "Down";
  46. }
  47. else
  48. {
  49. outputY += "Not sensing";
  50. }
  51.  
  52. if(digitalRead(6) == 1)
  53. {
  54. outputB += "Yes";
  55. digitalWrite(10, HIGH);
  56. }
  57. else
  58. {
  59. outputB += "No";
  60. digitalWrite(10, LOW);
  61. }
  62.  
  63. if(digitalRead(7) == 1)
  64. {
  65. outputA += "Yes";
  66. digitalWrite(13, HIGH);
  67. }
  68. else
  69. {
  70. outputA += "No";
  71. digitalWrite(13, LOW);
  72. }
  73.  
  74. Serial.println(outputX);
  75. Serial.println(outputY);
  76. Serial.println(outputB);
  77. Serial.println(outputA);
  78. }
Add Comment
Please, Sign In to add comment