Esempio n. 1
0
# only needed for testing
import os
import sys
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, parentdir)

from codebug_tether import CodeBug
import time
from random import randint

if len(sys.argv) != 3:
	print "Give two numbers as arguments"
	sys.exit(1)

def diceRoll():
	return randint(1,6)

if __name__ == '__main__':
	cb = CodeBug('/dev/tty.usbmodemfa141')
	cb.clear()
	delay = 0.2
	while True:
		if cb.get_input("A"):
			number = str(randint(int(sys.argv[1]), int(sys.argv[2])))
			for i in range(len(number) * 5 + 5):
				cb.write_text(5 - i, 0, number)
				time.sleep(delay)
			time.sleep(1)
Esempio n. 2
0
import datetime
from codebug_tether import CodeBug
import time
from random import randint

# if len(sys.argv) != 3:
# 	print "Give two numbers as arguments"
# 	sys.exit(1)


def displayString(displayString):
    for i in range(len(displayString) * 5 + 5):
        cb.write_text(5 - i, 0, displayString)
        time.sleep(delay)


if __name__ == "__main__":
    cb = CodeBug("/dev/tty.usbmodemfa141")
    cb.clear()
    delay = 0.2
    while True:
        if cb.get_input("A"):
            now = datetime.datetime.now()
            timeString = "TIME: {}:{}".format(now.hour, now.minute)
            displayString(timeString)

        elif cb.get_input("B"):
            now = datetime.datetime.now()
            dateString = "DATE: {}/{}/{}".format(now.day, now.month, now.year)
            displayString(dateString)
Esempio n. 3
0
tailY = headY
gameOver = False

# debug_directions = [FOWARD,CLOCKWISE,CLOCKWISE,FOWARD,FOWARD,CLOCKWISE,CLOCKWISE,FOWARD,ANTICLOCKWISE,ANTICLOCKWISE,FOWARD,FOWARD,FOWARD]

if __name__ == '__main__':
    cb = CodeBug('/dev/tty.usbmodemfa141')
    cb.clear()
    delay = 0.2
    for i, x in enumerate(snakeDirections):
        cb.set_led(headX + i, headY, 1)
    cb.set_led(headX + 1, headY, 1)

    while not gameOver:
        if counter % 2500000 == 2490000:
            if cb.get_input("A"):
                # if debug_directions[0] == ANTICLOCKWISE:
                if movement == NORTH:
                    movement = WEST
                else:
                    movement += ANTICLOCKWISE

            elif cb.get_input("B"):
                # elif debug_directions[0] == CLOCKWISE:
                movement = (movement + CLOCKWISE) % 4
            # del debug_directions[0]

            print directions[movement]
            print directions[snakeDirections[-1]]

            snakeDirections = [movement] + snakeDirections