EpixYaz
Posts: 5
Joined: Sun Jun 14, 2015 10:46 am

Joystick Error

Fri Jun 26, 2015 12:09 pm

This is probably the most common type of post in this forum but the joystick is not working. I have isolated the code as its quite long and it is a software error instead of hardware. I have read the guides posted on the RPi website and I believe that I'm doing it right. Here is the isolated version of the code:

Code: Select all

from astro_pi import AstroPi #Importing the AstroPi python library.
ap = AstroPi()
temp = ap.get_temperature()
Z = [255, 0, 0]
redhigh = [
Z, Z, Z, Z, Z, Z, Z, Z,
Z, Z, Z, Z, Z, Z, Z, Z,
Z, Z, Z, Z, Z, Z, Z, Z,  #Setting the individual neopixels to create a high red equilizer when values are above safe values
Z, Z, Z, Z, Z, Z, Z, Z,
Z, Z, Z, Z, Z, Z, Z, Z,
Z, Z, Z, Z, Z, Z, Z, Z,
Z, Z, Z, Z, Z, Z, Z, Z,
Z, Z, Z, Z, Z, Z, Z, Z
]
event.type = input(ap.show_message("Select variable screen"))
while event.type == KEYLEFT:
    while temp < 30:
        ap.set_pixels(redhigh)
Huge thanks in advance as I've spent almost three hours trying to fix it! :lol: :D

Joseph Burrell
Posts: 7
Joined: Mon May 25, 2015 6:23 pm

Re: Joystick Error

Fri Jun 26, 2015 4:28 pm

Hi, can I ask, do you know how to make it so that the temperature is displayed on one page, and when I move the joystick right, it shows the humidity... Please look at my post to see what I mean.

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1662
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Joystick Error

Sat Jun 27, 2015 7:56 pm

EpixYaz wrote:Huge thanks in advance as I've spent almost three hours trying to fix it! :lol: :D
The joystick works just like Up Down Left Right cursor keys, so it will also work outside of your program. You can move the menu highlight with it for example.

Try this:

Code: Select all

import pygame
import time

from pygame.locals import *
from astro_pi import AstroPi

pygame.init()
pygame.display.set_mode((640, 480))

ap = AstroPi()
Z = [255, 0, 0]

running = True

while running:
    temp = ap.get_temperature()
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_LEFT:
                while temp < 30:
                    ap.clear(Z)
                    time.sleep(.1)
                    temp = ap.get_temperature()  # you have to keep measuring the temp
            elif event.key == K_ESCAPE:
                running = False
P.S. I hope I've understood what you were trying to do? If you press left on the joystick then you display a red screen on the LED matrix if the temperature is below 30? And only if the temp goes above 30 do you carry on? That was the logic in the code you posted above.

You can use the ap.clear(Z) instead of using set_pixels with an array of red pixels.

EpixYaz
Posts: 5
Joined: Sun Jun 14, 2015 10:46 am

Re: Joystick Error

Sun Jun 28, 2015 12:39 pm

Yeah that was the general idea. @Davespice to the rescue again, many thanks!

Return to “Astro Pi”