16.Arduino learning notebook--PS2 rocker/game rocker experiment



16.Arduino learning notebook--PS2 rocker/game rocker experiment


          Juvtmall ( a company supply PCB PrototypingPCBA service and sell kinds of components, modules and so on) ( Catduino has the same function of Arduino) 


The PS2 rocker can be used to control the car, etc. The main structure is two 10K potentiometers and a key switch.The five ports are respectively VCC, X, Button, Y, GND.
Let's take a look at the picture






The old LCD screen is used to do other things, so use another one, different models of 1602 LCD to adjust the contrast of resistance value is different. So this time I will switch to a potentiometer, more convenient to adjust.
Hardware connection diagram


Download the code below to the arduino controller.
ARDUINO CODE

1. #include <LiquidCrystal. H > // call the LiquidCrystal library brought by arduino
2. 
3. LiquidCrystal LCD (12, 11, 10, 9, 8, 7);// setup interface
4. 
5. int xpotPin = 0;// set the analog port 0 as the signal input port of X
6. int ypotPin = 1;// set the analog port 1 as the signal input port of Y
7. int bpotPin = 2;// set the analog port 2 as the signal input port of Button
8. 
9. int xval = 0;// set variables
10. int yval = 0;
11. int bval = 0;
12. 
13. void setup ()
14.{
15. lcd. The begin (16, 2);// initialize LCD
16. delay (1000);/ / delay 1000 ms
17. }
18. 
19. void loop ()
20. {
21. 
22. xval = analogRead (xpotPin);//xval variable is the value read from the 0 signal port
23. yval = analogRead (ypotPin);//yval variable is the value read from the 1 signal port
24. bval = analogRead (bpotPin);//bval variable is the value read from the 2 signal port
25. lcd. The clear ();/ / clear screen
26. lcd. SetCursor (0, 0);// set the cursor position to the first position of the first row
27. lcd. Print (" X = ");// make the screen display text X=
28. lcd. Print (xval);
29. lcd. SetCursor (7, 0);// set the cursor position to the eighth position of the first row
30. lcd. Print (" Y = ");// make the screen display text Y=
31. lcd. Print (yval);
32. 
33. if (bval < 500)
34. {
35. lcd. SetCursor (0, 1);// set the cursor position to the first location of the second row
36. lcd. Print (" Button ON ");// make the screen display text Button ON
37. }
38. else
39. {
40. lcd. SetCursor (0, 1);
41. lcd. Print (" Button "OFF");// make the screen display text Button OFF
42. }
43. 
44. delay (100);// delay 0.1 second, which is the refresh rate.
45. 
46. }


Contact me: michelle1273110435@gmail.com

评论

此博客中的热门博文

9.Arduino learning notebook--Photocontrolled LED experiment

19.Arduino learning notebook--Atmega8 makes the minimum arduino system

17.Arduino learning notebook - stepper motors experiment