Sunday, August 3, 2014

X,Y coordinates in Joystick in Pygame

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


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


get_axis()
get the current position of an axis
get_axis(axis_number) -> float
Returns the current position of a joystick axis. The value will range from -1 to 1 with a value of 0 being centered. You may want to take into account some tolerance to handle jitter, and joystick drift may keep the joystick from centering at 0 or using the full range of position values.

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 

Raspberry Pi and DHT11 connection Diagram:


I just followed the instructions and finially I measured my room temperature and humidity.