Co-ordinates can be controlled easily with pygame joystick get_axis function.
joystick.get_axis(0) returns the 'x' axis position, at the same time
joystick.get_axis(1) returns the y axis position of the joystick. You can add to you rectangle image coordinates with the above values to make movement to the image in X,Y axis.
# get the rectangle the image occupies
# rec(x, y, w, h)
start_rect = image.get_rect()
image_rect = start_rect
.....
.....
.....
hor_x = joystick.get_axis(0)
hor_y = joystick.get_axis(1)
image_rect.left = image_rect.left+ hor_x * 2
image_rect.top = image_rect.top+ hor_y * 2
Sunday, August 3, 2014
Joystick Axis control with Pygame
Raspberry Pi joystick Pygames
As blogged before the screen image position controlling with joystick button are done. The good thing about electronic devices are that there will be many more things to explore further .Joy stick works as coordinates of the axis when we move it. Looks like its values moves from 1.0 to -1.0 . I am interested to control the screen image with this axis rather than buttons in the joystick.
Looking further on the documentation in Pygame - http://www.pygame.org/docs/ref/joystick.html
The axis number must be an integer from zero to get_numaxes()-1.
As blogged before the screen image position controlling with joystick button are done. The good thing about electronic devices are that there will be many more things to explore further .Joy stick works as coordinates of the axis when we move it. Looks like its values moves from 1.0 to -1.0 . I am interested to control the screen image with this axis rather than buttons in the joystick.
Looking further on the documentation in Pygame - http://www.pygame.org/docs/ref/joystick.html
- get_axis()
- get the current position of an axis
- get_axis(axis_number) -> float
The axis number must be an integer from zero to get_numaxes()-1.
Saturday, August 2, 2014
DHT11 connected to Raspberry Pi to measure Room Temperature & Humidity
As always the difficult part while interfacing a device especially sensors is the signal decoding. I always felt difficult to understand the specifications of a electronic device.
DHT11 decoding code and instructions I got from the below link