Exemplo n.º 1
0
greetings = [
    'Hi Tim!', 'How are you, Tim?', 'Howdy Tim!', 'Hello Tim!',
    'Hey there Tim!'
]  #the list of greetings that can be chosen


#choose random message
def pickMessage(messages):
    num_messages = len(messages)
    num_picked = randint(0, num_messages - 1)
    message_picked = messages[num_picked]
    return message_picked


#Greet Tim
ap.show_message(pickMessage(greetings))  #display a random greeting

#set up date/time
now = datetime.datetime.now()  #the current date
thisday = now.strftime("%m-%d")  #the current month and day

#take stats from station
StationTemp = 24  #We would get from sensor but Pi board gets hot so not accurate

#sort day and temperature into array
day = []
avTemp = []

#open file and read in the values for each column
with open('./heathrowWeather2014.tsv') as csvfile:
    csvReader = csv.reader(csvfile, delimiter="\t")
Exemplo n.º 2
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))
Exemplo n.º 3
0
                    #All the locations will be green
                    ap.set_pixel(places[0], places[1], snakeColour)

                #If the state is to turn things off
                if not state:
                    #Set all the pixels to black
                    ap.set_pixel(places[0], places[1], black)

            #If a pixel is out of range then instead of crashing just print "error"
            except ValueError:
                pass

        #Inverts the state
        if state:
            state = False

        else:
            state = True

        #Sleeps to allow for the visual flashing
        time.sleep(0.4)

#If you win show the won message in red
if check == "WON":
    ap.show_message("You won!", red)

fileObject = open("2Caterpillar/data.txt", "a")
fileObject.write("\n" + str(datetime.datetime.now()) + "," +
                 str(snakeBodyLength) + "," + str(survivalTime))
fileObject.close()
Exemplo n.º 4
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
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])
Exemplo n.º 6
0
        O = [255, 255, 255]  # White

        UK = [
        O, O, O, X, X, O, O, O,
        O, O, O, X, X, O, O, O,
        O, O, O, X, X, O, O, O,
        X, X, X, X, X, X, X, X,
        X, X, X, X, X, X, X, X,
        O, O, O, X, X, O, O, O,
        O, O, O, X, X, O, O, O,
        O, O, O, X, X, O, O, O
        ]

        ap.set_pixels(UK)
        time.sleep(6)
        ap.show_message("Hello ISS, you are over the UK")
        ap.show_message("Hello ISS. How are you!", text_colour=[255, 0, 0])
        

    ###FRANCE###
    elif (lati[0] <= 49 and lati[0] >= 43) and (longt[0] >= -3 and longt[0] <= 6):    
        print "FRANCE"

        X = [255, 0, 0]  # Red 
        O = [255, 255, 255]  # White 
        b= [0,0, 255] #Blue
        French_Flag  = [ 
        b, b, b, O, O, O, X, X,
        b, b, b, O, O, O, X, X, 
        b, b, b, O, O, O, X, X, 
        b, b ,b, O, O, O, X, X, 
Exemplo n.º 7
0
class AstroPiSnake():
    UP = 0
    DOWN = 1
    RIGHT = 2
    LEFT = 3

    BACKCOL = [0, 0, 0]
    SNAKECOL = [0, 255, 0]
    APPLECOL = [255, 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.5)
            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:
            newSegment[1] -= 1
        elif self.direction == self.DOWN:
            newSegment[1] += 1
        elif self.direction == self.LEFT:
            newSegment[0] -= 1
        elif self.direction == self.RIGHT:
            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
Exemplo n.º 8
0
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

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])
Exemplo n.º 10
0
            running = False
       #change the  co-efficient depending on the key pressed , or exit the game
        if event.type==KEYDOWN:
            if event.key==K_ESCAPE:
                running = False
            if event.key==K_LEFT:
                leftco = -1
                upco = 0
            elif event.key==K_RIGHT:
                leftco = 1
                upco = 0
            elif event.key==K_UP:
                leftco = 0
                upco = -1
            elif event.key==K_DOWN:
                leftco = 0
                upco = 1
    ap.set_pixel(x,y,0,0,0)

    now = time.time()
    #game exits after 60 seconds
    if(now - start > 60):
        running = False;
if(running == False):
    print("Finished")

#show the score beofre the game ends    
ap.show_message("points: " + str(points),0.2,[r,g,b])
ap.clear()
pygame.quit ()
Exemplo n.º 11
0
    endTime = datetime.datetime.now()
    totalTime = endTime - startTime

    timeTaken = (totalTime.seconds * 1000000) + totalTime.microseconds

    print(timeTaken / 1000, "miliseconds")
    return timeTaken / 1000


for i in range(3):
    playing = True
    while playing:
        cheat = countdown()
        if not cheat:
            time = reaction()
            ap.show_message(str(time), text_colour=[100, 0, 0])
            playing = False

        else:
            ap.show_message("Too Quick")
            playing = True

    fileObject = open("1Reaction/data.txt", "a")
    toWrite = "\n" + str(
        datetime.datetime.now()) + "," + str(time) + "," + direction
    fileObject.write(toWrite)
    fileObject.close()

pygame.quit()
Exemplo n.º 12
0
    
    endTime = datetime.datetime.now()
    totalTime = endTime - startTime

    timeTaken = (totalTime.seconds * 1000000) + totalTime.microseconds

    print(timeTaken/1000,"miliseconds")
    return timeTaken/1000

for i in range(3):
    playing = True
    while playing:
        cheat = countdown()
        if not cheat:
            time = reaction()
            ap.show_message(str(time), text_colour=[100,0,0])
            playing = False

        else:
            ap.show_message("Too Quick")
            playing = True

    fileObject = open("1Reaction/data.txt","a")
    toWrite = "\n"+str(datetime.datetime.now())+","+str(time)+","+direction
    fileObject.write(toWrite)
    fileObject.close()


pygame.quit()
Exemplo n.º 13
0
			r = [0,255,0]                          # green if higher
		elif hum_int == hum_prev:
			r = [0,0,255]                          # blue if the same
		else:
			r = [0,255,255]                        # light blue if lower
		hum_prev = hum_int
		image=TDG.numToMatrix(hum_int,back_colour=[0,0,0],text_colour=r)
		ap.set_pixels(image)
	elif y == -1 and x != -1:                      # temp display if USB ports pointing upwards
		ap.set_rotation(180)
		if temp_int > temp_prev:                   # Is the latest reading higher than the last?
			r = [255,0,0]                          # red if higher
		elif temp_int == temp_prev:
			r = [255,128,0]                        # orange if the same
		else:
			r = [255,215,0]                        # yellow if lower
		temp_prev = temp_int
		# use numToMatrix to turn the number into a 64 item list suitable for the LED
		image=TDG.numToMatrix(temp_int,back_colour=[0,0,0],text_colour=r)
		ap.set_pixels(image)
	elif x == 0 and y == 0:                        # if the Pi is flat on its back
		ap.show_message("Recording", text_colour=[150,150,150],scroll_speed=0.03) 
	else:
		ap.show_letter("?")                       # display a ? if at some other orientation

	time.sleep(dataDisplayInterval)
	sec_count+=1



e,e,e,g,g,e,e,e,
e,e,g,g,g,g,e,e,
e,g,e,g,g,e,g,e,
g,e,e,g,g,e,e,g,
e,e,e,g,g,e,e,e,
e,e,e,g,g,e,e,e,
e,e,e,g,g,e,e,e,
e,e,e,g,g,e,e,e
]

pause = 3
score = 0
angle = 0
play = True

ap.show_message("Keep the arrow pointing up",scroll_speed=0.05,text_colour=[100,100,100])

while play == True:
    last_angle = angle
    while angle == last_angle:
      angle = random.choice([0,90,180,270])
    ap.set_rotation(angle)
    ap.set_pixels(arrow)
    time.sleep(pause)

    x,y,z = ap.get_accelerometer_raw().values()
    x=round(x,0)
    y=round(y,0)

    print (angle)
    print (x)
Exemplo n.º 15
0
#message arrays
goodbyes = ['Bye bye!', 'Have a great day!', 'See you soon!', 'Goodbye Tim!'] #the list of goodbye messages that can be chosen
greetings = ['Hi Tim!', 'How are you, Tim?', 'Howdy Tim!', 'Hello Tim!', 'Hey there Tim!'] #the list of greetings that can be chosen


#choose random message
def pickMessage(messages):
    num_messages = len(messages)
    num_picked = randint(0, num_messages - 1)
    message_picked = messages[num_picked]
    return message_picked   


#Greet Tim
ap.show_message(pickMessage(greetings)) #display a random greeting


#set up date/time
now = datetime.datetime.now() #the current date
thisday = now.strftime("%m-%d") #the current month and day


#take stats from station
StationTemp = 24 #We would get from sensor but Pi board gets hot so not accurate


#sort day and temperature into array
day = []
avTemp = []
Exemplo n.º 16
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])
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)

    if t > 18.3 and t< 26.7:
        bg = [0,100,0] #green
    else:
        bg = [100,0,0] #red

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

    ap.show_message(msg,scroll_speed=0.05,backcolour=bg)
Exemplo n.º 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))
Exemplo n.º 19
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()


print("Temperature: %s C" % temp)               # Show temp on console
print("Humidity: %s %%rH" % humidity)        # Show humidity on console
print("Pressure: %s Millibars" % pressure)    # Show pressure on console

ap.set_rotation(180)        # Set LED matrix to scroll from right to left
              
ap.show_message("Temperature: %.2f C" % temp, scroll_speed=0.05, text_colour=[0, 255, 0])

time.sleep(1)           # Wait 1 second

ap.show_message("Humidity: %.2f %%rH" % humidity, scroll_speed=0.05, text_colour=[255, 0, 0]) 

time.sleep(1)      # Wait 1 second

ap.show_message("Pressure: %.2f Millibars" % humidity, scroll_speed=0.05, text_colour=[0, 0, 255])

ap.clear()      # Clear LED matrix
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
                if state:
                    #All the locations will be green
                    ap.set_pixel(places[0],places[1],snakeColour)

                #If the state is to turn things off
                if not state:
                    #Set all the pixels to black
                    ap.set_pixel(places[0],places[1],black)

            #If a pixel is out of range then instead of crashing just print "error"
            except ValueError:
                pass
            
        #Inverts the state
        if state:
            state = False

        else:
            state = True

        #Sleeps to allow for the visual flashing
        time.sleep(0.4)

#If you win show the won message in red
if check == "WON":
    ap.show_message("You won!", red)

fileObject = open("2Caterpillar/data.txt", "a")
fileObject.write("\n"+str(datetime.datetime.now())+","+str(snakeBodyLength)+","+str(survivalTime))
fileObject.close()