예제 #1
0
from codebug_tether import CodeBug
import time


if __name__ == '__main__':
    cb = CodeBug()
    for i in range(10):
        cb.set_row(0, 0b10101)
        cb.set_row(1, 0b01010)
        cb.set_row(2, 0b10101)
        cb.set_row(3, 0b01010)
        cb.set_row(4, 0b10101)
        time.sleep(1)
        cb.set_row(0, 0b01010)
        cb.set_row(1, 0b10101)
        cb.set_row(2, 0b01010)
        cb.set_row(3, 0b10101)
        cb.set_row(4, 0b01010)
        time.sleep(1)
예제 #2
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)
예제 #3
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)
예제 #4
0
# Mac
batteryCommand = ["pmset", "-g", "batt"]

def displayString(displayString):
	delay = 0.2
	if len(displayString) > 1:
		for i in range(len(displayString) * 5 + 5):
			cb.write_text(5 - i, 0, displayString)
			time.sleep(delay)
	else: 
		cb.write_text(0, 0, displayString)
		time.sleep(5)
	cb.clear()

if __name__ == '__main__':
	cb = CodeBug('/dev/tty.usbmodemfa141')
	cb.clear()
	while True:
		if cb.get_input("A"):
			outputString = subprocess.check_output(batteryCommand)
			# print outputString
			batteryLife = outputString.split("\t")[1].split("%")[0]
			# print batteryLife
			displayString(batteryLife+'%')

		elif cb.get_input("B"):
			outputString = subprocess.check_output(batteryCommand)
			batteryLife = int(outputString.split("\t")[1].split("%")[0])
			# print batteryLife
			rows = batteryLife/20
			# print rows
예제 #5
0
    def next_page(self, event=None):
        self.page += 1

    def previous_page(self, event=None):
        self.page -= 1


if __name__ == "__main__":
    try:
        search_term = sys.argv[1]
    except IndexError:
        search_term = None
        print("Using home timeline.")
    else:
        print("Searching for", search_term)

    twitter_creds = os.path.expanduser('~/.twitter_piface_demo_credentials')
    if not os.path.exists(twitter_creds):
        twitter.oauth_dance("CodeBug Tether Twitter", CONSUMER_KEY,
                            CONSUMER_SECRET, twitter_creds)

    oauth_token, oauth_secret = twitter.read_token_file(twitter_creds)

    codebug = CodeBug()

    global twitterticker
    twitterticker = TwitterTicker(codebug, oauth_token, oauth_secret,
                                  search_term)
    twitterticker.auto_update()  # start the updating process
예제 #6
0
        try:
            val = winreg.EnumValue(key, i)
            yield (str(val[1]))#, str(val[0]))
        except EnvironmentError:
            break

#Try and find open com port and then try to open them up
comPort = None
#comPort = 'com5'
#CB = CodeBug(comPort)
while comPort is None:
    esp = enumerate_serial_ports() # create a generator
    for i in esp:
        try:
            print "Testing " , i
            CB = CodeBug(i)
            CB.set(0,31)
            row0 = CB.get(0)
            print "This should be 31 if its a codebug. Value read = ", row0
            CB.set(0,0)
            if row0 == 31:
                print "Read/Write worked"
                print "CodeBug should be be on port" , i
                comPort = i
            time.sleep(1)
            break
        except Exception , e:
            print '"Exception ' , e
            pass

    if comPort is None:
예제 #7
0
import time
from codebug_tether import CodeBug


if __name__ == '__main__':
    cb = CodeBug()
    for i in range(10):
        cb.set_row(0, 0b10101)
        cb.set_row(1, 0b01010)
        cb.set_row(2, 0b10101)
        cb.set_row(3, 0b01010)
        cb.set_row(4, 0b10101)
        time.sleep(1)
        cb.set_row(0, 0b01010)
        cb.set_row(1, 0b10101)
        cb.set_row(2, 0b01010)
        cb.set_row(3, 0b10101)
        cb.set_row(4, 0b01010)
        time.sleep(1)
예제 #8
0
			0b00000,
			0b00100,
			0b00000,
			0b10001,],
		   [0b10001,
			0b00000,
			0b10001,
			0b00000,
			0b10001,]]

def diceRoll():
	return randint(0,5)

def drawSprite(number):
	sprite = sprites[number]
	for i, row in enumerate(sprite):
		cb.set_row(i, row)

if __name__ == '__main__':
    cb = CodeBug()
    cb.clear()
    while True:
    	if cb.get_input("A"):
    		cb.clear()
    		time.sleep(.5)
    		drawSprite(diceRoll())
    		time.sleep(1)



예제 #9
0
snakeDirections = [WEST, WEST, WEST]

counter = 0
levelcounter = 0
headX = 2
headY = 2
snakeLength = len(snakeDirections)
tailX = headX + snakeLength - 1
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
예제 #10
0
    0b00000,
    0b10001,
], [
    0b10001,
    0b00000,
    0b10001,
    0b00000,
    0b10001,
]]


def diceRoll():
    return randint(0, 5)


def drawSprite(number):
    sprite = sprites[number]
    for i, row in enumerate(sprite):
        cb.set_row(i, row)


if __name__ == '__main__':
    cb = CodeBug()
    cb.clear()
    while True:
        if cb.get_input("A"):
            cb.clear()
            time.sleep(.5)
            drawSprite(diceRoll())
            time.sleep(1)
예제 #11
0

def displayString(displayString):
    delay = 0.2
    if len(displayString) > 1:
        for i in range(len(displayString) * 5 + 5):
            cb.write_text(5 - i, 0, displayString)
            time.sleep(delay)
    else:
        cb.write_text(0, 0, displayString)
        time.sleep(5)
    cb.clear()


if __name__ == '__main__':
    cb = CodeBug('/dev/tty.usbmodemfa141')
    cb.clear()
    while True:
        if cb.get_input("A"):
            outputString = subprocess.check_output(batteryCommand)
            # print outputString
            batteryLife = outputString.split("\t")[1].split("%")[0]
            # print batteryLife
            displayString(batteryLife + '%')

        elif cb.get_input("B"):
            outputString = subprocess.check_output(batteryCommand)
            batteryLife = int(outputString.split("\t")[1].split("%")[0])
            # print batteryLife
            rows = batteryLife / 20
            # print rows
예제 #12
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)
예제 #13
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


if __name__ == '__main__':
    cb = CodeBug()
    cb.clear()
    for i in range(0x20):
        cb.set_row(0, i)
        time.sleep(1)
예제 #14
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

if __name__ == '__main__':
    cb = CodeBug()
    cb.clear()
    for i in range(0x20):
        cb.set_row(0, i)
        time.sleep(1)