Astro Pi – Projecto CEF 1

 

O projeto desta equipa foi concluído e já foi submetido.

Foi criada uma aplicação semelhante a uma agenda que permite organizar o dia-a-dia do astronauta na Estação Espacial Internacional. Esta aplicação exibe na matriz de leds do astroPi uma imagem referente à atividade que o astronauta deverá realizar naquela hora. As atividades previstas são: dormir, comer, ginásio, trabalho, lazer.

 

Código da aplicação em python:

#!/usr/bin/python


## Astronaut Time Manager
## Program to help astronauts to manage time and tasks 
## Program starts in play mode. In this mode LED matrix show an image of the task assign to the current time
## There are a few tasks assigned by default. User may change, remove ou add new tasks to diary.
## When exit program all data are saved to be used next time.
## In play mode:
##                  return to setMode                               (joystick RETURN) 
##                  consult following tasks                         (RIGHT button)
##                  consult current time                            (LEFT button)
##                  exit program                                    (a button)          
##
## In setMode: (letters 'H' and 'm' are set to RED)
##                  change hours and minutes for any task ,         (UP and DOWN button)
##                  consult all task, one by one                    (RIGHT button) 
##                  delete tasks                                    (a button)
##                  add new tasks                                   (b button)
##                  return to playMode                              (joystick RETURN)

import os,sys, math, pygame
from pygame.locals import *
from sense_hat import SenseHat
from datetime import time, datetime
from time import sleep

# Colors --------------------------------------------------------
X= [0,0,0]
R= [255,0,0]
G = [0,255,0]
B = [0,0,255]
Y = [255,255,0]
M = [255,0,255]
C = [0,255,255]
W = [255, 255, 255]

# Task logos -----------------------------------------------------
EAT  = [X,X,X,X,X,X,X,X,
        X,W,X,W,X,X,W,X,
        X,W,X,W,X,W,W,X,
        X,W,X,W,X,W,W,X,
        X,X,W,X,X,W,W,X,
        X,X,B,X,X,X,B,X,
        X,X,B,X,X,X,B,X,
        X,X,B,X,X,X,B,X]

SLEEP= [X,X,X,X,X,M,M,X,
        X,X,M,M,X,X,M,X,
        X,X,X,M,X,X,M,M,
        B,X,X,M,M,X,X,X,
        B,W,X,X,X,X,X,X,
        B,C,W,W,W,W,W,B,
        B,B,B,B,B,B,B,B,
        B,X,X,X,X,X,X,B,]
             
GYM  = [X,X,X,X,X,X,X,X,
        X,X,W,X,X,W,X,X,
        X,W,W,X,X,W,W,X,
        B,W,W,B,B,W,W,B,
        X,W,W,X,X,W,W,X,
        X,X,W,X,X,W,X,X,
        X,X,X,X,X,X,X,X,
        X,X,X,X,X,X,X,X,]

PLAY = [X,X,X,X,X,X,X,X,
        W,R,W,W,W,W,R,W,
        R,R,R,W,W,R,R,R,
        W,R,W,W,W,W,R,W,
        W,W,W,X,X,W,W,W,
        W,W,W,X,X,W,W,W,
        X,X,X,X,X,X,X,X,
        X,X,X,X,X,X,X,X]

WORK = [R,X,X,X,R,G,G,G,
        R,X,R,X,R,G,X,G,
        X,R,X,R,X,G,G,G,
        B,B,B,B,W,X,X,W,
        B,X,X,B,W,X,W,X,
        B,B,B,B,W,W,X,X,
        B,X,B,X,W,X,W,X,
        B,X,X,B,W,X,X,W]

# Data structures -----------------------------------------------------------------

tasks =(SLEEP,EAT,WORK,PLAY,GYM)
diary =[[6,00,1],[7,00,2],[11,00,4],[12,00,1],[13,00,2],[17,00,3],[19,00,1],[20,00,3],[21,00,0]]

# auxiliar functions --------------------------------------------------------------

# Set pixels in LED matrix 
def set_pixels(pixels, col):
    for p in pixels:
        astroPi.set_pixel(p[0], p[1], col[0], col[1], col[2])

# numberToPixels returns the necessary pixels to show in LED matrix the number num
def numberToPixels(num):
    return{
        0:   [[0,0],[1,0],[2,0],[0,1],[2,1],[0,2],[2,2],[0,3],[2,3],[0,4],[1,4],[2,4]],     
        1:   [[1,0],[0,1],[1,1],[1,2],[1,3],[0,4],[1,4],[2,4]],
        2:   [[0,0],[1,0],[2,0],[2,1],[0,2],[1,2],[2,2],[0,3],[0,4],[1,4],[2,4]],
        3:   [[0,0],[1,0],[2,0],[2,1],[1,2],[2,2],[2,3],[0,4],[1,4],[2,4]],
        4:   [[0,0],[2,0],[0,1],[2,1],[0,2],[1,2],[2,2],[2,3],[2,4]],  
        5:   [[0,0],[1,0],[2,0],[0,1],[0,2],[1,2],[2,2],[2,3],[0,4],[1,4],[2,4]],
        6:   [[0,0],[1,0],[2,0],[0,1],[0,2],[1,2],[2,2],[0,3],[2,3],[0,4],[1,4],[2,4]],
        7:   [[0,0],[1,0],[2,0],[2,1],[1,2],[0,3],[0,4]],
        8:   [[0,0],[1,0],[2,0],[0,1],[2,1],[0,2],[1,2],[2,2],[0,3],[2,3],[0,4],[1,4],[2,4]],
        9:   [[0,0],[1,0],[2,0],[0,1],[2,1],[0,2],[1,2],[2,2],[2,3],[0,4],[1,4],[2,4]],
        'h': [[5,0],[7,0],[5,1],[6,1],[7,1],[5,2],[7,2]],
        'm': [[4,0],[6,0],[3,1],[5,1],[7,1],[3,2],[5,2],[7,2]],
        't': [[0,0],[1,0],[2,0],[1,1],[1,2]]
        }[num]

# Show number num in the LED matrix
def numberToLED(timeType,number,colour):
    d=math.trunc(number/10)
    u=number%10
    for i in numberToPixels(timeType):
        astroPi.set_pixel(i[0],i[1],colour)
    for i in numberToPixels(d):
        astroPi.set_pixel(i[0]+1,i[1]+3,W)
    for i in numberToPixels(u):
        astroPi.set_pixel(i[0]+5,i[1]+3,W)

# PlayMode ----------------------------------------------------------
def playMode(astroPi,currentEntry):
    global currentMode
    play = True
    currentSection=0
    entry = len(diary)-1
    while play:
        for i in range(len(diary)):
            myTime = time(diary[i][0],diary[i][1])
            if myTime<datetime.time(datetime.now()):
                entry=i
        if currentEntry != entry:
            currentEntry =entry
        astroPi.set_pixels(tasks[diary[currentEntry][2]])
        #manage button events in playMode
        for event in pygame.event.get():
            if event.type == KEYDOWN:
                if event.key == pygame.K_a:         # Button a
                    diary.sort(key= lambda tup:(tup[0],tup[1]))
                    with open(fileName,'w') as f:
                        for i in range (len(diary)):
                            strDiary= str(diary[i][0])+' '+str(diary[i][1])+' '+str(diary[i][2])+'\n'
                            f.write(strDiary)
                    f.close()
                    astroPi.clear(0,0,0)
                    sys.exit(0)                    
                elif event.key == pygame.K_RETURN:  # joystick RETURN
                    play = False
                    currentMode="set"
                elif event.key == pygame.K_r:       # Button RIGHT
                    nextEntry = (currentEntry+1)%len(diary)
                    astroPi.clear(0,0,0)
                    numberToLED('h',diary[nextEntry][0],R)
                    sleep(1)
                    astroPi.clear(0,0,0)
                    numberToLED('m',diary[nextEntry][1],R)
                    sleep(1)
                    astroPi.clear(0,0,0)
                    astroPi.set_pixels(tasks[diary[nextEntry][2]])
                    sleep(1)
                elif event.key == pygame.K_l:       # Button LEFT
                    astroPi.clear()
                    numberToLED('h',datetime.now().hour,G)
                    sleep(1)
                    astroPi.clear()
                    numberToLED('m',datetime.now().minute,G)
                    sleep(1)
                    astroPi.clear()
    
# setMode -------------------------------------------------------------------------
def setMode(astroPi):
    global currentMode   
    setmode =True
    currentEntry=0
    currentSection=0
    
    astroPi.clear()
    numberToLED('h',diary[currentEntry][0],R)
    while setmode:
        size = len(diary)
        #manage button events in setMode
        for event in pygame.event.get():
            if event.type == KEYDOWN:
                if event.key == pygame.K_RETURN:
                    setmode = False
                    currentMode="play"
                elif event.key == pygame.K_u:           # Button UP   
                    if(currentSection==0):
                        diary[currentEntry][0]=(diary[currentEntry][0]+1)%24
                    elif(currentSection==1):
                        diary[currentEntry][1]=(diary[currentEntry][1]+1)%60
                    else:
                        diary[currentEntry][2]=(diary[currentEntry][2]+1)%len(tasks)
                elif event.key == pygame.K_d:           # Button DOWN
                    if(currentSection==0):
                        diary[currentEntry][0]=(diary[currentEntry][0]-1)%24
                    elif(currentSection==1):
                        diary[currentEntry][1]=(diary[currentEntry][1]-1)%60
                    else:
                        diary[currentEntry][2]=(diary[currentEntry][2]-1)%len(tasks)
                elif event.key == pygame.K_l:           # Button LEFT
                    if currentSection == 2:
                        currentSection = 1
                    else:
                        currentSection=0      
                elif event.key == pygame.K_r:           # Button RIGHT
                    if currentSection == 2:
                        aux=diary[currentEntry]
                        diary.sort(key= lambda tup:(tup[0],tup[1]))         
                        currentEntry= (diary.index(aux)+1)%size
                        currentSection = 0        
                    else:
                        currentSection +=1
                elif event.key == pygame.K_a:          # Button a       
                    if size==1:
                        diary.clear()
                        diary.append([0,0,0])
                    else:
                        diary.remove(diary[currentEntry])
                        if currentEntry==size-1:
                            currentEntry=0
                            currentSection=0                          
                elif event.key == pygame.K_b:           # Button b
                    diary.append([0,0,0])
                    diary.sort(key= lambda tup:(tup[0],tup[1]))
                    currentEntry=0
                    currentSection=0
                astroPi.clear()
                if currentSection==0:
                    numberToLED('h',diary[currentEntry][0],R)
                elif currentSection==1:
                    numberToLED('m',diary[currentEntry][1],R)
                else:
                    astroPi.set_pixels(tasks[diary[currentEntry][2]])              
                
# main program ------------------------------------------------------------------
pygame.init()
pygame.display.set_mode((640, 480))
astroPi = SenseHat()
astroPi.clear()  # Blank the LED matrix
astroPi.set_rotation(270)  # Flight orientation

fileName="astroPi_diary.txt"
# read previous data if exists
exists=os.path.isfile(fileName)
if exists:
    diary.clear()
    with open(fileName,newline='') as f:
        for line in f:
            entry=[int(i) for i in line.split()]
            diary.append(entry)

currentEntry = len(diary)-1

for i in range(len(diary)):
    myTime = time(diary[i][0],diary[i][1])
    if myTime<datetime.time(datetime.now()):
        currentEntry=i
astroPi.set_pixels(tasks[diary[currentEntry][2]])

currentMode= "play"
running = True

while running:
    currentHour=datetime.now().hour
    currentMin=datetime.now().minute
    if currentMode == "play":
        playMode(astroPi,currentEntry)
    if currentMode=="set":
        setMode(astroPi)

 

March 3, 2017

Tags: ,
  • As you will inevitably learn on your path to losing weight, effective weight loss is not only about watching what you eat, but much more about changing your lifestyle. This means changing your habits and how you approach your day-to-day life. Read this information to help you throughout the process.

  • Some people, especially those running on busy daily schedules tend to use the pills to help maintain weight since they can not afford to follow all the diet programs. This is not advised. It is recommended that one seek advice from a professional in this field before using the pills. This can save one from many dangers associated with the misuse.

    The diet pills should always be taken whole. Some people tend to divide the pills to serve a longer period of time. This is not advised and can lead to ineffectiveness. If it is required that one takes a complete tablet, it means that a certain amount of the ingredients are required to achieve the desired goal. It is also recommended that one does not crush the pill and dissolve it in beverages. Chemicals found in beverages have the potential of neutralizing the desired nutrients in the pill thereby leading to ineffectiveness. The best way to take the tablets is swallowing them whole with a glass of water.

    The diet pills speed up the metabolic processes. This is the key factor that leads to the burning of all the fats in the body. This means that one passes out lots of urine, which subsequently leads to dehydration. It is imperative that the user take lots of water round the clock. This will help curb dehydration, which can lead to health problems. In addition to that, water offers the required medium for the function of the nutrients and elimination of the fats.

    When buying the review of diet pills, it is imperative that one gets the most recommended dose. People tend to compromise the quality and effectiveness of the tablets due to the variation in cost. The low priced pills depict poor quality, which means their effectiveness is not reliable. Some have also been found to cause health problems. The dose should also be taken as recommended. Over dose will not speed up the process but rather lead to complication. This will increase risk of side effects. If the taking of the pill is forgotten, do not take more to compensate for the lost time.

    The diet plan enclosed with the diet pills has also to be followed. According to the requirements, the termination of the diet must be done even with no results. This means your body is irresponsive.

  • Leave a Reply

    Your email address will not be published. Required fields are marked *