コード例 #1
0
        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():
                mcap.interact(blockHit.pos)
            # keep reading the astro pi orientation data otherwise it goes out of sync
            ap.get_orientation()
コード例 #2
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)
コード例 #3
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)
コード例 #4
0
	if num == '9':
		return sing_9
	if num == '0':
		return sing_0

# set previous humidity value to zero

hum_prev = 0

# Main program loop

while True:

# Get humidity from astro-pi

	hum_f = ap.get_humidity()
	hum_int = int(hum_f)
# test to see if value is higher or lower than previous, and then set led colour appropriately 
	logging.info(hum_f)
	if hum_int > hum_prev:
		r = [0,255,0] # green if higher
	elif hum_int == hum_prev:
		r = [255,127,0] # orange if the same
	else:
		r = [255,0,0] # red if lower
	hum_prev = hum_int
	hum =  str(hum_int) # convert reading to string
	image = numToMatrix(hum[1]) + space + numToMatrix(hum[0]) # build image from two digits plus spacer
	ap.set_pixels(image)
	time.sleep(0.5)
コード例 #5
0
        while arrow == last_arrow:
          arrow = random.choice([0,90,180,270])

        ap.set_rotation(arrow)
 
        num = random.random()
        if num > 0.1:
            plot_image(shake_img,w,bl)
            time.sleep(pause)
            if shake_check():
                plot_image(shake_img,g,bl)
                score = score + 1
            else:
                plot_image(shake_img,r,bl)
                lives = lives -1
        elif num > 0.9 and ap.get_humidity()<60:
            hum = ap.get_humidity()
            plot_image(breath_img,w,bl)
            time.sleep(pause)
            if ap.get_humidity() > hum + 4:
                plot_image(breath_img,g,bl)
                score = score + 1
            else:
                plot_image(breath_img,r,bl)
                lives = lives - 1
        else:
            plot_image(arrow_img,w,bl)
            time.sleep(pause)
            if  get_angle() == arrow:
                plot_image(arrow_img,g,bl)
                score = score + 1
コード例 #6
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)
コード例 #7
0
        return sing_9
    if num == '0':
        return sing_0


# set previous humidity value to zero

hum_prev = 0

# Main program loop

while True:

    # Get humidity from astro-pi

    hum_f = ap.get_humidity()
    hum_int = int(hum_f)
    # test to see if value is higher or lower than previous, and then set led colour appropriately
    logging.info(hum_f)
    if hum_int > hum_prev:
        r = [0, 255, 0]  # green if higher
    elif hum_int == hum_prev:
        r = [255, 127, 0]  # orange if the same
    else:
        r = [255, 0, 0]  # red if lower
    hum_prev = hum_int
    hum = str(hum_int)  # convert reading to string

    # add a leading zero for single digit readings
    if hum_int < 10:
        hum = '0' + hum
コード例 #8
0
ファイル: readsensors.py プロジェクト: astro-pi/SpaceCRAFT
# 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)
コード例 #9
0
ファイル: HTLogger.py プロジェクト: topshed/HTLogger
tmstmp = time.strftime("%Y%m%d-%H%M%S")           # Set timestamp format for the logging filename
logging.basicConfig(format='%(asctime)s %(message)s',filename='readings'+str(tmstmp)
+'.log',level=logging.DEBUG)                      # set up logging

hum_prev = 0                                      # set previous humidity and temp values to zero
temp_prev = 0
sec_count = 0

while True:                                       # Main program loop

	x, y, z = ap.get_accelerometer_raw().values() #Get raw accelerometer values and round them
	x = round(x, 0)
	y = round(y, 0)
	temp_f = ap.get_temperature()                 # Get temperature from astro-pi
	hum_f = ap.get_humidity()                     # Get humidity from astro-pi
	hum_int = int(hum_f)                          # convert to integers
	temp_int = int(temp_f)

	if (sec_count >= dataWriteInterval/dataDisplayInterval) or (sec_count == 0): 
		logging.info('humidity: ' + str(hum_f) + ' temperature: ' + str(temp_f))
		sec_count = 0

	if x == -1 and y != -1:                        # humidity display if HDMI port pointing upwards
		ap.set_rotation(270)
		if hum_int > hum_prev:                     # Is the latest reading higher than the last?
			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