tronicyaka

Arduino Basic #3 | Joystick Module

Dec 30th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. int x;
  2. int y;
  3.  
  4. void setup()
  5. {
  6. Serial.begin(9600);
  7.  
  8. pinMode(8,OUTPUT);
  9. pinMode(9,OUTPUT);
  10. pinMode(10,OUTPUT);
  11. pinMode(11,OUTPUT);
  12. pinMode(12,OUTPUT);
  13. pinMode(A0, INPUT);
  14. pinMode(A1, INPUT);
  15. }
  16.  
  17.  
  18. void loop()
  19. {
  20. x=analogRead(A0);
  21. y=analogRead(A1);
  22.  
  23. Serial.println("x y");
  24. Serial.print(x);
  25. Serial.print(" ");
  26. Serial.println(y);
  27.  
  28. if(x>550){
  29. digitalWrite(8,HIGH);
  30. digitalWrite(9,LOW);
  31. digitalWrite(10,LOW);
  32. digitalWrite(11,LOW);
  33. digitalWrite(12,LOW);
  34. }
  35.  
  36. else if(y>525){
  37. digitalWrite(8,LOW);
  38. digitalWrite(9,LOW);
  39. digitalWrite(10,LOW);
  40. digitalWrite(11,HIGH);
  41. digitalWrite(12,LOW);
  42. }
  43.  
  44. else if(x<500){
  45. digitalWrite(8,LOW);
  46. digitalWrite(9,HIGH);
  47. digitalWrite(10,LOW);
  48. digitalWrite(11,LOW);
  49. digitalWrite(12,LOW);
  50. }
  51.  
  52. else if(y<475){
  53. digitalWrite(8,LOW);
  54. digitalWrite(9,LOW);
  55. digitalWrite(10,LOW);
  56. digitalWrite(11,LOW);
  57. digitalWrite(12,HIGH);
  58. }
  59.  
  60. else if(x>500 && x<550){
  61. digitalWrite(8,LOW);
  62. digitalWrite(9,LOW);
  63. digitalWrite(10,HIGH);
  64. digitalWrite(11,LOW);
  65. digitalWrite(12,LOW);
  66. }
  67.  
  68. delay(100);
  69. }
Add Comment
Please, Sign In to add comment