Exemple #1
0
parentdir = os.path.dirname(currentdir)
from PiStorms import PiStorms

# starts an instance of PiStorms
psm = PiStorms()

### setup variables ###
# exit is used to eventually exit the main running loop
# score will keep track of the player's current score
# dispScore tracks the displayed score
exit = False
score = 1
dispScore = -1

# turns the leds off from any previous program
psm.led(1, 0, 0, 0)
psm.led(2, 0, 0, 0)

# sets screen to a white background
psm.screen.fillRect(0, 0, 320, 240)

# initial loading screen
psm.screen.fillBmp(110,
                   20,
                   100,
                   100,
                   path=currentdir + '/' + "faceAwesome.png")
psm.screen.drawAutoText("Hi I am Mike!", 15, 140, fill=(0, 0, 0), size=30)
psm.screen.drawAutoText("Catch me if you can!!",
                        15,
                        170,
Exemple #2
0
                print 'f.set()'
        sleep(0.1)
    psm.led(1, 0, 0, 0)


if __name__ == "__main__":

    entered_house = Event()
    found_bomb = Event()
    got_victim = Event()

    f_thread = Thread(target=follow, args=(entered_house, found_bomb, got_victim))
    f_thread.start()
    s_thread = Thread(target=search, args=(entered_house, found_bomb, got_victim))
    s_thread.start()

    while not exit:

        sleep(0.05)

        if psm.isKeyPressed(): # if the GO button is pressed
            psm.screen.clearScreen()
            psm.screen.termPrintln("Exiting to menu")
            psm.led(1,0,0,0)    
            psm.BAM1.float()
            psm.BAM2.float()
            psm.BBM1.float()
            psm.BBM2.float() 
            sleep(0.1)
            exit = True
Exemple #3
0
    psm.BBM2.float()


if __name__ == '__main__':

    psm.BAM1.resetPos()
    ramp(RAMP_UP)

    while not psm.isKeyPressed():
        psm.screen.termPrintln('waiting')

    psm.screen.clearScreen()
    psm.screen.termPrintln('starting!')

    for i in xrange(5):
        psm.led(1, 255, 0, 0)
        sleep(0.8)
        psm.led(1, 0, 0, 0)
        sleep(0.2)

    psm.screen.clearScreen()
    ramp(RAMP_MID)
    sleep(0.5)

    Thread(target = go).start()

    while not exit:
        sleep(0.05)

        if psm.isKeyPressed():
              psm.screen.clearScreen()
psm = PiStorms() # PiStorms object
exit = False    # break loop

while (not exit):
    light = psm.BBS1.lightSensorNXT(True)
    #       520
    error = 540 - light #if within 40 on edge, if negative on line, if positive in white 
    # psm.BBM1.setSpeedSync(30)
    # if (abs(error) < 20): #on edge
	# psm.BBM1.setSpeedSync(30)
	# psm.led(1,0,255,0) #green
    if (error < 0): #on line, turn to right, left wheel accelerate
  	psm.BBM1.setSpeed(25)
	psm.BBM2.setSpeed(-50)
	psm.led(1,0,0,255)#blue
    elif (error > 0): #on white, turn to left, right wheel accelerate
	psm.BBM2.setSpeed(25)
	psm.BBM1.setSpeed(-50)
	psm.led(1,255,0,0)#Red
    sleep(0.1)

    if (psm.isKeyPressed()): #exit
        psm.BBM1.brakeSync()
	psm.led(1,0,0,0)
	psm.screen.clearScreen()
	psm.screen.termPrintln("")
	psm.screen.termPrintln("Exiting to menu")
	sleep(0.5)
	exit = True
#starts an instance of PiStorms

ev3l = EV3Lights()
psm = PiStorms()
#exit variable will be used later to exit the program and return to PiStormsMaster
doExit = False

psm.screen.termPrintln("EV3Lights Demo")
psm.screen.termPrintln("connect mindsensors.com's ")
psm.screen.termPrintln("EV3Lights to BAS1 sensor Port")
psm.screen.termPrintln("")
psm.screen.termPrintln("")
psm.screen.termPrintln("")
psm.screen.termPrintln("")
psm.screen.termPrintln("Press GO button to exit")
psm.led(1, 0,0,0)
psm.led(2, 0,0,0)

psm.BAS1.activateCustomSensorI2C() #Connect the I2C sensor on the port BBS1
time.sleep(.1)
#main loop
# This test program will print IMU data on Terminal
# Compass heading is represented on Red LED on BANKB
# Program will exit when someone touch the screen or Go Button

time_gap = 0.5

while(not doExit):
    #
    try:
        psm.led(1, 100,0,0)
Exemple #6
0
sys.path.insert(0,parentdir) 
from PiStorms import PiStorms
psm = PiStorms()

psm.screen.termPrintln("Battery Voltage")
psm.screen.termPrintln(" ")

psm.BBS1.resetTouchesEV3()
exit = False
lastled = 0
while(not exit):
    voltVal = psm.battVoltage()
    psm.screen.termReplaceLastLine(str(voltVal) + "V")

    if(voltVal >= 8and lastled != 1):
        psm.led(1,0,255,0)
        psm.led(2,0,255,0)
        lastled = 1
    if(voltVal < 8 and voltVal > 6 and lastled != 2):
        psm.led(1,0,255,0)
        psm.led(2,0,255,0)
        lastled = 2
    if(voltVal <= 6 and lastled != 3):
        psm.led(1,255,0,0)
        psm.led(2,255,0,0)
        lastled = 3
    if(psm.screen.isTouched()):
        psm.screen.termPrintln("")
        psm.screen.termPrintln("Exiting to menu")
        psm.led(1,0,0,0)
        psm.led(2,0,0,0)
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0,parentdir)

#starts an instance of PiStorms

imu=ABSIMU()
psm = PiStorms()
#exit variable will be used later to exit the program and return to PiStormsMaster
doExit = False

psm.screen.termPrintln("AbsIMU test")
psm.screen.termPrintln("connect mindsensors.com's ")
psm.screen.termPrintln("AbsImu to BAS1 sensor Port")
psm.led(1, 0,0,0)
psm.led(2, 0,0,0)

psm.BAS1.activateCustomSensorI2C() #Connect the I2C sensor on the port BBS1
time.sleep(.1)
#main loop
# This test program will print IMU data on Terminal
# Compass heading is represented on Red LED on BANKB
# Program will exit when someone touch the screen or Go Button

while(not doExit):
    #
    try:
        heading = imu.get_heading()
        accl = imu.get_accelall()
        mag = imu.get_magall()
Exemple #8
0
#starts an instance of PiStorms

ev3l = EV3Lights()
psm = PiStorms()
#exit variable will be used later to exit the program and return to PiStormsMaster
doExit = False

psm.screen.termPrintln("EV3Lights Demo")
psm.screen.termPrintln("connect mindsensors.com's ")
psm.screen.termPrintln("EV3Lights to BAS1 sensor Port")
psm.screen.termPrintln("")
psm.screen.termPrintln("")
psm.screen.termPrintln("")
psm.screen.termPrintln("")
psm.screen.termPrintln("Press GO button to exit")
psm.led(1, 0, 0, 0)
psm.led(2, 0, 0, 0)

psm.BAS1.activateCustomSensorI2C()  #Connect the I2C sensor on the port BBS1
time.sleep(.1)
#main loop
# This test program will print IMU data on Terminal
# Compass heading is represented on Red LED on BANKB
# Program will exit when someone touch the screen or Go Button

time_gap = 0.5

while (not doExit):
    #
    try:
        psm.led(1, 100, 0, 0)
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)

#starts an instance of PiStorms

imu = ABSIMU()
psm = PiStorms()
#exit variable will be used later to exit the program and return to PiStormsMaster
exit = False

#clears the screen of any unwanted text by displaying a white rectangle
#psm.screen.fillRect(0, 0, 320, 240)
psm.screen.termPrintln("Custom I2C test program")
psm.screen.termPrintln("connect mindsensors.com's ")
psm.screen.termPrintln("AbsImu on port BBS1 ")
psm.led(1, 0, 0, 0)
psm.led(2, 0, 0, 0)

psm.BBS1.activateCustomSensorI2C()  #Connect the I2C sensor on the port BBS1
#main loop
# This test program will print IMU data on Terminal
# Compass heading is represented on Red LED on BANKB
# Program will exit when someone touch the screen or Go Button

while (not exit):
    #
    try:
        heading = imu.get_heading()
        accl = imu.get_accelall()
        mag = imu.get_magall()
        gyro = imu.get_gyroall()
Exemple #10
0
#please support mindsensors.com  by purchasing products from mindsensors.com!
#Learn more product option visit us @  http://www.mindsensors.com/

# Tic Tac Toe

import random
import os,sys,inspect,time,thread
import socket,fcntl,struct

currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0,parentdir)
from PiStorms import PiStorms

psm = PiStorms()
psm.led(1,0,0,0)
psm.led(2,0,0,0)


def drawLines():
    #210x210, 55px side border, 15px vertical border,  70px squares
    psm.screen.fillRect(124,15, 2,210)
    psm.screen.fillRect(196,15, 2,210)
    psm.screen.fillRect(55,84, 210,2)
    psm.screen.fillRect(55,154, 210,2)

def drawBoard(board):
    # This function prints out the board that it was passed.
    # "board" is a list of 10 strings representing the board (ignore index 0)

    k = { 'X': {
Exemple #11
0
        "LED-sample", "This feature is not implemented on",
        "PiStorms Firmware: V2.04 and earlier.",
        "Please upgrade your PiStorms.", "  ", "Click OK to exit."
    ]
    psm.screen.askQuestion(m, ["OK"])
    exit = True
else:
    exit = False
    psm.screen.termPrintAt(8, "Press Go button to exit")

d1 = 0.2
d2 = 0.2
oldKeyPressCount = psm.getKeyPressCount()
while (not exit):

    psm.led(2, 0, 255, 0)
    time.sleep(d1)
    psm.led(1, 0, 255, 0)
    time.sleep(d2)
    psm.led(2, 255, 0, 0)
    time.sleep(d1)
    psm.led(1, 255, 0, 0)
    time.sleep(d2)
    psm.led(2, 0, 0, 255)
    time.sleep(d1)
    psm.led(1, 0, 0, 255)
    time.sleep(d2)

    newKeyPressCount = psm.getKeyPressCount()
    if (newKeyPressCount > oldKeyPressCount):
        psm.screen.termPrintln("")
ev3ultrasonic_BBS1 = LegoDevices.EV3UltrasonicSensor("BBS1")


psm.screen.drawDisplay('Sensor Demo', True)
psm.screen.termPrintln('NXT Touch Sensor at BAS1')
psm.screen.termPrintln('EV3 Touch Sensor at BAS2')
psm.screen.termPrintln('EV3 Ultrasonic Sensor at BBS1')
time.sleep(1)

# This section requires two touch sensors. Connect them to Bank 1
# and press one by one to turn LED green. If they are both pressed at
# the same time, the LED will turn purple and the program will stop.
while not (nxttouch_BAS1.isPressed() and ev3touch_BAS2.isPressed()):
  if nxttouch_BAS1.isPressed():
    psm.led(1, 51, 255, 51)
  else:
    psm.led(1, 255, 0, 0)
  if ev3touch_BAS2.isPressed():
    psm.led(2, 51, 255, 51)
  else:
    psm.led(2, 255, 0, 0)
  time.sleep(0.1)
psm.led(1, 102, 0, 204)
psm.led(2, 102, 0, 204)
time.sleep(2)
psm.led(1, 0, 0, 0)
psm.led(2, 0, 0, 0)

# Scans the distance 5 times
psm.screen.termPrintln('Starting distance sensor')
ev3touch_BAS2 = LegoDevices.EV3TouchSensor("BAS2")

ev3ultrasonic_BBS1 = LegoDevices.EV3UltrasonicSensor("BBS1")

psm.screen.drawDisplay('Sensor Demo', True)
psm.screen.termPrintln('NXT Touch Sensor at BAS1')
psm.screen.termPrintln('EV3 Touch Sensor at BAS2')
psm.screen.termPrintln('EV3 Ultrasonic Sensor at BBS1')
time.sleep(1)

# This section requires two touch sensors. Connect them to Bank 1
# and press one by one to turn LED green. If they are both pressed at
# the same time, the LED will turn purple and the program will stop.
while not (nxttouch_BAS1.isPressed() and ev3touch_BAS2.isPressed()):
    if nxttouch_BAS1.isPressed():
        psm.led(1, 51, 255, 51)
    else:
        psm.led(1, 255, 0, 0)
    if ev3touch_BAS2.isPressed():
        psm.led(2, 51, 255, 51)
    else:
        psm.led(2, 255, 0, 0)
    time.sleep(0.1)
psm.led(1, 102, 0, 204)
psm.led(2, 102, 0, 204)
time.sleep(2)
psm.led(1, 0, 0, 0)
psm.led(2, 0, 0, 0)

# Scans the distance 5 times
psm.screen.termPrintln('Starting distance sensor')