Chapter 12 Joystick
140
28
29
30
31
32
33
34
35
36
37
38
39
40
41
time
.
sleep
(
0.01
)
d e f
destroy
():
bus
.
close
()
GPIO
.
cleanup
()
i f
__name__
= =
'__main__'
:
p r int
(
'Program is starting ... '
)
setup
()
t r y
:
loop
( )
e x cept
KeyboardInterrupt
:
destroy
()
In the code, configure Z_Pin to pull-up input mode. In while cycle of loop, use
analogRead
() to read the
value of axis X and Y and use
GPIO.input
() to read the value of axis Z, then print them out.
w h ile
T r ue
:
val_Z
=
GPIO
.
input
(
Z_Pin
)
#read digital quality of axis Z
val_Y
=
analogRead
(
0
)
#read analog quality of axis X and Y
val_X
=
analogRead
(
1
)
p r int
(
'value_X: %d ,\tvlue_Y: %d ,\tvalue_Z: %d'
% (
val_X
,
val_Y
,
val_Z
))
time
.
sleep
(
0.01
)
Summary of Contents for Ultimate Starter Kit
Page 1: ...Free your innovation Freenove is an open source electronics platform www freenove com ...
Page 117: ...117 Chapter 9 Potentiometer RGBLED www freenove com support freenove com Hardware connection ...
Page 155: ...155 Chapter 14 Relay Motor www freenove com support freenove com Hardware connection OFF 3 3V ...
Page 173: ...173 Chapter 16 Stepping Motor www freenove com support freenove com Hardware connection ...
Page 239: ...239 Chapter 22 Matrix Keypad www freenove com support freenove com Circuit Schematic diagram ...
Page 240: ...Chapter 22 Matrix Keypad 240 www freenove com support freenove com Hardware connection ...