예제 #1
0
    def __init__(
        self, fb_device="/dev/fb1", imu_settings_file="RTIMULib", text_assets="astro_pi_text", sample_rate=0.01
    ):

        self.sample_rate = sample_rate

        AstroPi.__init__(self, fb_device, imu_settings_file, text_assets)

        self._orientation = AstroPi.get_orientation(self)

        # start the orientation thread
        thread.start_new_thread(self._get_orientation_threaded, ())
예제 #2
0
 def _get_orientation_threaded(self):
     """
     Internal. called in a thread to continuously read the astro pi data
     """
     self.stopped = False
     self.running = True
     while not self.stopped:
         self._orientation = AstroPi.get_orientation(self)
         sleep(self.sample_rate)
     self.running = False
from astro_pi import AstroPi
import time
ap = AstroPi()

w = [150,150,150]
b = [0,0,255]
e = [0,0,0]

image = [
e,e,e,e,e,e,e,e,
e,e,e,e,e,e,e,e,
w,w,w,e,e,w,w,w,
w,w,b,e,e,w,w,b,
w,w,w,e,e,w,w,w,
e,e,e,e,e,e,e,e,
e,e,e,e,e,e,e,e,
e,e,e,e,e,e,e,e
]

ap.set_pixels(image)

while True:
    time.sleep(1)
    ap.flip_h()
from astro_pi import AstroPi
import time
import random
ap = AstroPi()

# set up the colours (white, green, red, empty)

w = [150,150,150]
g = [0,255,0]
r = [255,0,0]
e = [0,0,0]

# create images for three different coloured arrows

arrow = [
e,e,e,w,w,e,e,e,
e,e,w,w,w,w,e,e,
e,w,e,w,w,e,w,e,
w,e,e,w,w,e,e,w,
e,e,e,w,w,e,e,e,
e,e,e,w,w,e,e,e,
e,e,e,w,w,e,e,e,
e,e,e,w,w,e,e,e
]
arrow_red = [
e,e,e,r,r,e,e,e,
e,e,r,r,r,r,e,e,
e,r,e,r,r,e,r,e,
r,e,e,r,r,e,e,r,
e,e,e,r,r,e,e,e,
e,e,e,r,r,e,e,e,
from astro_pi import AstroPi
ap = AstroPi()
import time

ap.show_letter("J")

while True:
  x,y,z = ap.get_accelerometer_raw().values()

  x=round(x,0)
  y=round(y,0)

  if x == -1:
      ap.set_rotation(180)
  elif y == 1:
      ap.set_rotation(90)
  elif y == -1:
      ap.set_rotation(270)
  else:
      ap.set_rotation(0)

  time.sleep(0.1)
from astro_pi import AstroPi

ap = AstroPi()

while True:
    ap.show_message("Astro Pi is awesome!!",
                    scroll_speed=0.05,
                    text_colour=[255, 255, 0],
                    back_colour=[0, 0, 255])
예제 #7
0
#19/05/15
import pygame, random, datetime, time
from pygame.locals import *
from astro_pi import AstroPi

ap = AstroPi()

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


def handle_event(event):
    if event.key == pygame.K_DOWN:
        return "DOWN"

    elif event.key == pygame.K_UP:
        return "UP"

    elif event.key == pygame.K_LEFT:
        return "LEFT"

    elif event.key == pygame.K_RIGHT:
        return "RIGHT"

    elif event.key == pygame.K_RETURN:
        return "RETURN"


#Gets a joystick input with optional timeout
def joystick(timeout=-1):
    running = True
from astro_pi import AstroPi
ap = AstroPi()
while True:
    ap.show_message("Astro Pi is awesome!!",scroll_speed=0.05,text_colour=[255,255,0],back_colour=[0,0,255])
from astro_pi import AstroPi


ap = AstroPi()

r = [255,0,0]
o = [255,127,0]
y = [255,255,0]
g = [0,255,0]
b = [0,0,255]
i = [75,0,130]
v = [159,0,255]
e = [0,0,0]

image = [
e,e,e,e,e,e,e,e,
e,e,e,r,r,e,e,e,
e,r,r,o,o,r,r,e,
r,o,o,y,y,o,o,r,
o,y,y,g,g,y,y,o,
y,g,g,b,b,g,g,y,
b,b,b,i,i,b,b,b,
b,i,i,v,v,i,i,b
]

ap.set_pixels(image)
from astro_pi import AstroPi
import pygame
import picamera
from pygame.locals import *
import sweaty_astronaut_framed as saf
import RPi.GPIO as GPIO

UP=26
DOWN=13
RIGHT=19
LEFT=20
A=16
B=21
GPIO.setmode(GPIO.BCM)

ap = AstroPi()
ap.set_rotation(270)

def button_pressed(button):
    #written by Richard
	global ap
	global pressed
	#print(button)
	pressed = 1
	
for pin in [UP, DOWN, LEFT, RIGHT, A, B]:
        
    GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP)
    GPIO.add_event_detect(pin, GPIO.FALLING, callback=button_pressed, bouncetime=100)

# Logging code by Alfie
예제 #11
0
#30/05/15

import pygame, random, datetime, time
from pygame.locals import *
from astro_pi import AstroPi

ap = AstroPi()

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

#Handle the joystick input
def handle_event(event):
    if event.key == pygame.K_DOWN:
        return "DOWN"
        
    elif event.key == pygame.K_UP:
        return "UP"

    elif event.key == pygame.K_LEFT:
        return "LEFT"

    elif event.key == pygame.K_RIGHT:
        return "RIGHT"

    elif event.key == pygame.K_RETURN:
        return "RETURN"



#Gets a joystick input with optional timeout        
예제 #12
0
#reading orientation data in a loop, if you dont read it fast enough it goes out of sync
from astro_pi import AstroPi
from time import sleep

ap = AstroPi()

ap.set_imu_config(True, True, True)

while (True):
    orientation = ap.get_orientation_degrees()
    print("yaw = {}; pitch = {}; roll = {}".format(orientation["yaw"],
                                                   orientation["pitch"],
                                                   orientation["roll"]))

    sleep(0.1)
예제 #13
0
# Magic 8 Ball

import random
import time
from astro_pi import AstroPi

ap = AstroPi()

ap.show_message("Ask a question & shake", scroll_speed=(0.06))
time.sleep(3)

replies = [
    'Signs point to yes', 'Without a doubt', 'You may rely on it',
    'Do not count on it', 'Looking good', 'Cannot predict now',
    'It is decidedly so', 'Outlook not so good'
]

while True:
    x, y, z = ap.get_accelerometer_raw().values()

    x = abs(x)
    y = abs(y)
    z = abs(z)

    if x > 2 or y > 2 or z > 2:
        ap.show_message(random.choice(replies), scroll_speed=(0.06))
    else:
        ap.clear()
예제 #14
0
#reading sensor data in a loop
from astro_pi import AstroPi
from time import sleep

ap = AstroPi()

while(True):
    pressure = ap.get_pressure()
    print(pressure)

    humidity = ap.get_humidity()
    print(humidity)

    temp = ap.get_temperature_from_pressure()
    print(temp)

    temp = ap.get_temperature_from_humidity()
    print(temp)

    orientation = ap.get_orientation_degrees()
    print(orientation["yaw"])
    print(orientation["pitch"])
    print(orientation["roll"])

    orientation = ap.get_orientation_radians()
    print(orientation["yaw"])
    print(orientation["pitch"])
    print(orientation["roll"])

    sleep(1)
예제 #15
0
#!/usr/bin/python
import time
from astro_pi import AstroPi

ap = AstroPi()

pixels = [
    [255, 0, 0], [255, 0, 0], [255, 87, 0], [255, 196, 0], [205, 255, 0], [95, 255, 0], [0, 255, 13], [0, 255, 122],
    [255, 0, 0], [255, 96, 0], [255, 205, 0], [196, 255, 0], [87, 255, 0], [0, 255, 22], [0, 255, 131], [0, 255, 240],
    [255, 105, 0], [255, 214, 0], [187, 255, 0], [78, 255, 0], [0, 255, 30], [0, 255, 140], [0, 255, 248], [0, 152, 255],
    [255, 223, 0], [178, 255, 0], [70, 255, 0], [0, 255, 40], [0, 255, 148], [0, 253, 255], [0, 144, 255], [0, 34, 255],
    [170, 255, 0], [61, 255, 0], [0, 255, 48], [0, 255, 157], [0, 243, 255], [0, 134, 255], [0, 26, 255], [83, 0, 255],
    [52, 255, 0], [0, 255, 57], [0, 255, 166], [0, 235, 255], [0, 126, 255], [0, 17, 255], [92, 0, 255], [201, 0, 255],
    [0, 255, 66], [0, 255, 174], [0, 226, 255], [0, 117, 255], [0, 8, 255], [100, 0, 255], [210, 0, 255], [255, 0, 192],
    [0, 255, 183], [0, 217, 255], [0, 109, 255], [0, 0, 255], [110, 0, 255], [218, 0, 255], [255, 0, 183], [255, 0, 74]
]

msleep = lambda x: time.sleep(x / 1000.0)


def next_colour(pix):
    r = pix[0]
    g = pix[1]
    b = pix[2]

    if (r == 255 and g < 255 and b == 0):
        g += 1

    if (g == 255 and r > 0 and b == 0):
        r -= 1
예제 #16
0
파일: pisnake.py 프로젝트: raynardj/rpi
class AstroPiSnake():
    UP = 0
    DOWN = 1
    RIGHT = 2
    LEFT = 3

    BACKCOL = [0, 0, 0]
    SNAKECOL = [50, 50, 100]
    APPLECOL = [100, 0, 0]

    def __init__(self):
        pygame.init()
        pygame.display.set_mode((640, 480))

        self.ap = AstroPi()

    def startGame(self):
        self.ap.clear(self.BACKCOL)
        self.direction = self.UP
        self.length = 3
        self.tail = []
        self.tail.insert(0, [4, 4])
        self.createApple()
        self.score = 0

        playing = True
        while (playing):
            sleep(0.2)
            for event in pygame.event.get():
                if event.type == KEYDOWN:
                    self._handle_event(event)
            playing = self.move()

        self.ap.clear()

    def _handle_event(self, event):
        if event.key == pygame.K_DOWN:
            self.down()
        elif event.key == pygame.K_UP:
            self.up()
        elif event.key == pygame.K_LEFT:
            self.left()
        elif event.key == pygame.K_RIGHT:
            self.right()

    def createApple(self):
        badApple = True
        #try and fnd a location for the apple
        while (badApple):
            x = randint(0, 7)
            y = randint(0, 7)
            badApple = self.checkCollision(x, y)
        self.apple = [x, y]
        self.ap.set_pixel(x, y, self.APPLECOL)

    def checkCollision(self, x, y):
        #is this outside the screen
        if x > 7 or x < 0 or y > 7 or y < 0:
            return True
        else:
            #or in the snakes tail
            for segment in self.tail:
                if segment[0] == x and segment[1] == y:
                    return True
            else:
                return False

    def addSegment(self, x, y):
        #create the new segment of the snake
        self.ap.set_pixel(x, y, self.SNAKECOL)
        self.tail.insert(0, [x, y])

        #do I need to clear a segment
        if len(self.tail) > self.length:
            lastSegment = self.tail[-1]
            self.ap.set_pixel(lastSegment[0], lastSegment[1], self.BACKCOL)
            self.tail.pop()

    def move(self):
        #work out where the new segment of the snake will be
        newSegment = [self.tail[0][0], self.tail[0][1]]
        if self.direction == self.UP:
            if newSegment[1] == 0:
                newSegment[1] = 7
            else:
                newSegment[1] -= 1
        elif self.direction == self.DOWN:
            if newSegment[1] == 7:
                newSegment[1] = 0
            else:
                newSegment[1] += 1
        elif self.direction == self.LEFT:
            if newSegment[0] == 0:
                newSegment[0] = 7
            else:
                newSegment[0] -= 1
        elif self.direction == self.RIGHT:
            if newSegment[0] == 7:
                newSegment[0] = 0
            else:
                newSegment[0] += 1

        if self.checkCollision(newSegment[0], newSegment[1]):
            #game over
            snakehead = self.tail[0]
            for flashHead in range(0, 5):
                self.ap.set_pixel(snakehead[0], snakehead[1], self.SNAKECOL)
                sleep(0.2)
                self.ap.set_pixel(snakehead[0], snakehead[1], self.BACKCOL)
                sleep(0.2)
            self.ap.show_message("Score = {}".format(self.score),
                                 text_colour=self.APPLECOL)

        else:
            self.addSegment(newSegment[0], newSegment[1])

            #has the snake eaten the apple?
            if newSegment[0] == self.apple[0] and newSegment[1] == self.apple[
                    1]:
                self.length += 1
                self.score += 10
                self.createApple()

            return True

    def up(self):
        if self.direction != self.DOWN:
            self.direction = self.UP

    def down(self):
        if self.direction != self.UP:
            self.direction = self.DOWN

    def left(self):
        if self.direction != self.RIGHT:
            self.direction = self.LEFT

    def right(self):
        if self.direction != self.LEFT:
            self.direction = self.RIGHT
from astro_pi import AstroPi
import time
import logging
from datetime import datetime

ap = AstroPi()

r = [255, 0, 0]
e = [0, 0, 0]

space = [
    e,
    e,
    e,
    e,
    e,
    e,
    e,
    e,
    e,
    e,
    e,
    e,
    e,
    e,
    e,
    e,
]
tmstmp = time.strftime("%Y%m%d-%H%M%S")
logging.basicConfig(format='%(asctime)s %(message)s',
                    filename='humidity' + str(tmstmp) + '.log',
예제 #18
0
# Magic 8 Ball

import random
import time
from astro_pi import AstroPi

ap = AstroPi()

ap.show_message("Ask a question", scroll_speed=(0.06))
time.sleep(3)

replies = [
    'Signs point to yes', 'Without a doubt', 'You may rely on it',
    'Do not count on it', 'Looking good', 'Cannot predict now',
    'It is decidedly so', 'Outlook not so good'
]

ap.show_message(random.choice(replies), scroll_speed=(0.06))
예제 #19
0
import pygame, random, datetime, time, math
import time as ti
from pygame.locals import *
from astro_pi import AstroPi

ap = AstroPi()

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

def handle_event(event):
    if event.key == pygame.K_DOWN:
        return "DOWN"
        
    elif event.key == pygame.K_UP:
        return "UP"
        
    elif event.key == pygame.K_LEFT:
        return "LEFT"
        
    elif event.key == pygame.K_RIGHT:
        return "RIGHT"
        
    elif event.key == pygame.K_RETURN:
        return "RETURN"
    
#Gets a joystick input with optional timeout
#This version of the of joystick checks the time regularaly which is less efficient
#But that allows for a higher degree of accuracy which was needed as the speed of
#The ball is relatively high
def joystick(timeout=-1):
예제 #20
0
        Clears the mc astro pi
        """
        self.ap.clear()
        self.mcastropi.clear()


# run
if __name__ == "__main__":

    print("SpaceCRAFT - Minecraft Interactive Astro Pi")

    # create connection to minecraft
    mc = Minecraft.create()

    # create the astro pi object
    ap = AstroPi()
    # read data from the astro pi to initialise it
    ap.get_orientation()
    ap.get_humidity()
    ap.get_pressure()

    # find the players position and create the astro pi 10 blocks above them
    pos = mc.player.getTilePos()
    pos.y += 10
    mcap = MCInteractiveAstroPi(mc, ap, pos)

    try:
        print("CTRL C to quit")
        while True:
            # each time a block is hit pass it to the interactive astro pi
            for blockHit in mc.events.pollBlockHits():
예제 #21
0
import pygame, random, datetime, time
from pygame.locals import *
from astro_pi import AstroPi

#Length; Survival

ap = AstroPi()

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


#Handle the joystick input
def handle_event(event):
    if event.key == pygame.K_DOWN:
        return "DOWN"

    elif event.key == pygame.K_UP:
        return "UP"

    elif event.key == pygame.K_LEFT:
        return "LEFT"

    elif event.key == pygame.K_RIGHT:
        return "RIGHT"

    elif event.key == pygame.K_RETURN:
        return "RETURN"


#Gets a joystick input with optional timeout
예제 #22
0
from astro_pi import AstroPi
import pygame
import picamera
from pygame.locals import *
import sweaty_astronaut_framed as saf
import RPi.GPIO as GPIO

UP = 26
DOWN = 13
RIGHT = 19
LEFT = 20
A = 16
B = 21
GPIO.setmode(GPIO.BCM)

ap = AstroPi()
ap.set_rotation(270)


def button_pressed(button):
    #written by Richard
    global ap
    global pressed
    #print(button)
    pressed = 1


for pin in [UP, DOWN, LEFT, RIGHT, A, B]:

    GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP)
    GPIO.add_event_detect(pin,
예제 #23
0
from astro_pi import AstroPi

ap = AstroPi()

humidity = ap.get_humidity()

print("Humidity", humidity)



from astro_pi import AstroPi

ap = AstroPi()

r = [255,0,0]
o = [255,127,0]
y = [255,255,0]
g = [0,255,0]
b = [0,0,255]
i = [75,0,130]
v = [159,0,255]
e = [0,0,0]

image = [
e,e,e,e,e,e,e,e,
e,e,e,r,r,e,e,e,
e,r,r,o,o,r,r,e,
r,o,o,y,y,o,o,r,
o,y,y,g,g,y,y,o,
y,g,g,b,b,g,g,y,
b,b,b,i,i,b,b,b,
b,i,i,v,v,i,i,b
]

ap.set_pixels(image)
ap.set_rotation(180)
예제 #25
0
#!/usr/bin/python
from astro_pi import AstroPi
import time

ap = AstroPi()
temp = ap.get_temperature()
humidity = ap.get_humidity()
pressure = ap.get_pressure()

while True:
    ap.set_rotation(180)

    print("Temperature: %s C" % temp)
    ap.show_message("Temperature: %.1f C" % temp, scroll_speed=0.1, text_colour$
    time.sleep(1)

    print("Humidity: %.2f %%rH" % humidity)
    ap.show_message("Humidity: %.1f %%rH" % humidity, scroll_speed=0.1, text_co$
    time.sleep(1)

    print("Pressure: %.2f mb" % pressure)
    ap.show_message("Pressure: %.1f mb" % pressure, scroll_speed=0.1, text_colo$
    time.sleep(1)

ap.clear()
from astro_pi import AstroPi
import time
import random
ap = AstroPi() 

try:
    with open("score","r") as scorefile:
        highscore = int(scorefile.read())
except IOError:
    highscore = 0

#set up the colours (white,green,red,empty)
w = [150,150,150]
g = [0,255,0]
r = [255,0,0]
bl = [0,0,0]

#create images for three different coloured arrows
arrow_img = [0,0,0,1,1,0,0,0,0,0,1,1,1,1,0,0,0,1,0,1,1,0,1,0,1,0,0,1,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0]
button_img = [0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,1,0,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,0,1,0,0,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0]
shake_img =_img = [0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0]
breath_img =_img = [0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,1,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,1,0,0,1,1,0,0,0,0,1,1,0]

def plot_image(pattern,fg,bg):
    image =[]
    for pixel in pattern:
        if pixel == 0:
            image.append(bg)
        else:
            image.append(fg)
    ap.set_pixels(image)
from astro_pi import AstroPi

ap = AstroPi()

ap.set_pixel(2,2,[0,0,255])
ap.set_pixel(4,2,[0,0,255])
ap.set_pixel(3,4,[100,0,0])
ap.set_pixel(1,5,[255,0,0])
ap.set_pixel(2,6,[255,0,0])
ap.set_pixel(3,6,[255,0,0])
ap.set_pixel(4,6,[255,0,0])
ap.set_pixel(5,5,[255,0,0])
예제 #28
0
#reading orientation data in a loop, if you dont read it fast enough it goes out of sync
from astro_pi import AstroPi
from time import sleep

ap = AstroPi()

ap.set_imu_config(True, True, True)

while(True):
    orientation = ap.get_orientation_degrees()
    print("yaw = {}; pitch = {}; roll = {}".format(orientation["yaw"], orientation["pitch"], orientation["roll"]))

    sleep(0.1)

예제 #29
0
# 30/05/15

import pygame, random, datetime, time
from pygame.locals import *
from astro_pi import AstroPi

ap = AstroPi()

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

# Handle the joystick input
def handle_event(event):
    if event.key == pygame.K_DOWN:
        return "DOWN"

    elif event.key == pygame.K_UP:
        return "UP"

    elif event.key == pygame.K_LEFT:
        return "LEFT"

    elif event.key == pygame.K_RIGHT:
        return "RIGHT"

    elif event.key == pygame.K_RETURN:
        return "RETURN"


# Gets a joystick input with optional timeout
def joystick(timeout=-1):
예제 #30
0
#!/usr/bin/python
from astro_pi import AstroPi

ap = AstroPi()
ap.set_rotation(180)
ap.show_message("One small step for Pi!", text_colour=[255, 0, 0])
예제 #31
0
find_match = 0  #this is used when looping through the file so that it stops looking when a match is found

#columns in text file
dayColumn = 1  #the column number of the day column
tempColumn = 2  #the column number of the temperature column
rainColumn = 6  #the column number of the rainfall column
cloudColumn = 4  #the column number of the cloud cover column

#Arrays to read data into
dayArr = []  #the array to put the days into
avTempArr = []  #the array to put the temperatures into
avRainArr = []  #the array to put the rainfall data into
avCloudArr = []  #the array to put the cloud cover data into

#initiate AstroPi
ap = AstroPi()

#filenames
iconFileName = ""
sunPng = "sun.png"  #this is the sunny weather icon
cloudPng = "cloud.png"  #this is the cloudy weather icon
sunCloudPng = "sunncloud.png"  #this is the sunny/cloudy weather icon
lightRainPng = "light rain.png"  #this is the light rain weather icon
heavyRainPng = "heavy rain.png"  #this is the heavy rain weather icon
pngPath = "./"  #this is the path to the icons relative to this script

#weather range values
valueSun = 3  #less than 3 hours cloud therefore sunny
valueCloudSun = 5  #between valueSun and valueCloudSun then cloudy/sunny
NoRain = 1  #less than 1 then no rain
LightRain = 10  # more than this is heavy rain otherwise light rain
예제 #32
0
#!/usr/bin/python
import time
from astro_pi import AstroPi

ap = AstroPi()

r = 255
g = 0
b = 0

msleep = lambda x: time.sleep(x / 1000.0)


def next_colour():
    global r
    global g
    global b

    if (r == 255 and g < 255 and b == 0):
        g += 1

    if (g == 255 and r > 0 and b == 0):
        r -= 1

    if (g == 255 and b < 255 and r == 0):
        b += 1

    if (b == 255 and g > 0 and r == 0):
        g -= 1

    if (b == 255 and r < 255 and g == 0):
예제 #33
0
#05/06/15
import pygame, random, datetime, math, os, time
from pygame.locals import *
from astro_pi import AstroPi

ap = AstroPi()

ap.clear()

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


#Handle the joystick input
def handle_event(event):
    if event.key == pygame.K_DOWN:
        return "DOWN"

    elif event.key == pygame.K_UP:
        return "UP"

    elif event.key == pygame.K_LEFT:
        return "LEFT"

    elif event.key == pygame.K_RIGHT:
        return "RIGHT"

    elif event.key == pygame.K_RETURN:
        return "RETURN"

예제 #34
0
파일: pisnake.py 프로젝트: raynardj/rpi
    def __init__(self):
        pygame.init()
        pygame.display.set_mode((640, 480))

        self.ap = AstroPi()
예제 #35
0
# Magic 8 Ball

import random
import time
from astro_pi import AstroPi

ap = AstroPi()

ap.show_message("Ask a question", scroll_speed=(0.06))
time.sleep(3)

replies = [
    "Signs point to yes",
    "Without a doubt",
    "You may rely on it",
    "Do not count on it",
    "Looking good",
    "Cannot predict now",
    "It is decidedly so",
    "Outlook not so good",
]

ap.show_message(random.choice(replies), scroll_speed=(0.06))
예제 #36
0
#testing the led matrix
from astro_pi import AstroPi

ap = AstroPi()

ap.clear()

#ap.show_message("Hello Space")

ap.set_pixel(0, 0, 255, 0, 0)

ap.set_pixel(7, 7, 255, 255, 255)

#ap.set_pixel(7, 7, 0, 0, 0)

ap.clear()

#ap.clear([0,0,255])
예제 #37
0
#read all astro pi sensors
#a test to see how quick it is

from time import time, sleep
from astro_pi import AstroPi

ap = AstroPi()
ap.get_humidity()
ap.get_pressure()
ap.get_orientation()

while (True):
    starttime = time()

    hum = ap.get_humidity()
    pres = ap.get_pressure()
    temp1 = ap.get_temperature_from_humidity()
    temp1 = ap.get_temperature_from_pressure()
    rads = ap.get_orientation_radians()
    degs = ap.get_orientation_degrees()
    rawcomp = ap.get_compass_raw()
    rawgyro = ap.get_gyroscope_raw()
    rawaccel = ap.get_accelerometer_raw()

    endtime = time()

    print(endtime - starttime)
    sleep(1)
from astro_pi import AstroPi
import time
import logging
from datetime import datetime


ap = AstroPi()

r = [255, 0, 0]
e = [0, 0, 0]

space = [
e,e,e,e,e,e,e,e,
e,e,e,e,e,e,e,e,
]
tmstmp = time.strftime("%Y%m%d-%H%M%S")
logging.basicConfig(format='%(asctime)s %(message)s',filename='humidity'+str(tmstmp)
+'.log',level=logging.DEBUG)

def numToMatrix(num):

# define 1x8 columns that make  single digits when combined

	num_1_2 = [e,e,r,e,e,e,r,e]
	num_1_1 = [e,r,r,r,r,r,r,e]
	num_1_0 = [e,e,e,e,e,e,r,e]

	num_2_2 = [e,r,e,e,e,r,r,e]
	num_2_1 = [e,r,e,e,r,e,r,e]
	num_2_0 = [e,r,r,r,e,e,r,e]
예제 #39
0
#!/usr/bin/python
from astro_pi import AstroPi

ap = AstroPi()
ap.clear()
ap.load_image("space_invader.png")
예제 #40
0
from astro_pi import AstroPi

ap = AstroPi()

pressure = ap.get_pressure()

print("Pressure", pressure)



예제 #41
0
import pygame, random, datetime, time, math
import time as ti
from pygame.locals import *
from astro_pi import AstroPi

ap = AstroPi()

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


def handle_event(event):
    if event.key == pygame.K_DOWN:
        return "DOWN"

    elif event.key == pygame.K_UP:
        return "UP"

    elif event.key == pygame.K_LEFT:
        return "LEFT"

    elif event.key == pygame.K_RIGHT:
        return "RIGHT"

    elif event.key == pygame.K_RETURN:
        return "RETURN"


#Gets a joystick input with optional timeout
#This version of the of joystick checks the time regularaly which is less efficient
#But that allows for a higher degree of accuracy which was needed as the speed of
from astro_pi import AstroPi
ap = AstroPi()

while True:
    t = ap.get_temperature()
    p = ap.get_pressure()
    h = ap.get_humidity()

    t = round(t,1)
    p = round(p,1)
    h = round(h,1)

    msg = "Temperature = %s, Pressure=%s, Humidity=%s" % (t,p,h)

    ap.show_message(msg,scroll_speed=0.05)
예제 #43
0
from astro_pi import AstroPi

ap = AstroPi()

tempHumidity = ap.get_temperature_from_humidity()
tempPressure = ap.get_temperature_from_pressure()

print("Temp Humidity", tempHumidity)
print("Temp Pressure", tempPressure)

#hum = ap.get_humidity()

#print(hum)


예제 #44
0
#05/06/15
import pygame, random, datetime, math, os, time
from pygame.locals import *
from astro_pi import AstroPi
ap = AstroPi()


ap.clear()

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


#Handle the joystick input
def handle_event(event):
    if event.key == pygame.K_DOWN:
        return "DOWN"
        
    elif event.key == pygame.K_UP:
        return "UP"

    elif event.key == pygame.K_LEFT:
        return "LEFT"

    elif event.key == pygame.K_RIGHT:
        return "RIGHT"

    elif event.key == pygame.K_RETURN:
        return "RETURN"

예제 #45
0
from astro_pi import AstroPi

ap = AstroPi()

humidity = ap.get_humidity()

print("Humidity", humidity)
예제 #46
0
#!/usr/bin/python
import os
import time
import pygame  # See http://www.pygame.org/docs

print("Press Escape to quit")
time.sleep(1)

from pygame.locals import *
from astro_pi import AstroPi

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

ap = AstroPi()
ap.clear()  # Blank the LED matrix

# 0, 0 = Top left
# 7, 7 = Bottom right
UP_PIXELS = [[3, 0], [4, 0]]
DOWN_PIXELS = [[3, 7], [4, 7]]
LEFT_PIXELS = [[0, 3], [0, 4]]
RIGHT_PIXELS = [[7, 3], [7, 4]]
CENTRE_PIXELS = [[3, 3], [4, 3], [3, 4], [4, 4]]


def set_pixels(pixels, col):
    for p in pixels:
        ap.set_pixel(p[0], p[1], col[0], col[1], col[2])

예제 #47
0
import pygame, random, datetime
import time as ti
from pygame.locals import *
from astro_pi import AstroPi

ap = AstroPi()

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


def handle_event(event):
    if event.key == pygame.K_DOWN:
        return "DOWN"

    elif event.key == pygame.K_UP:
        return "UP"

    elif event.key == pygame.K_LEFT:
        return "LEFT"

    elif event.key == pygame.K_RIGHT:
        return "RIGHT"

    elif event.key == pygame.K_RETURN:
        return "RETURN"


#Gets a joystick input with optional timeout
def joystick(timeout=-1):
    running = True