Exemple #1
0
def run(n):
    lcd = pyb.LCD('X')
    lcd.light(1)
    m = mpr121.MPR121(pyb.I2C(1, pyb.I2C.MASTER))

    def blob(x, y, w, h, fill):
        for i in range(w):
            for j in range(h):
                if pyb.rng() & 0xff < fill:
                    lcd.pixel(x + i, y + j, 1)

    for i in range(n):
        t = m.touch_status()
        lcd.fill(0)
        for y in range(32):
            lcd.pixel(64, y, 1)
        for x in range(128):
            lcd.pixel(x, 16, 1)
        if t & 1:
            blob(90, 20, 10, 10, 316 - m.elec_voltage(0))
        if t & 2:
            blob(30, 20, 10, 10, 316 - m.elec_voltage(1))
        if t & 4:
            blob(90, 5, 10, 10, 316 - m.elec_voltage(2))
        if t & 8:
            blob(30, 5, 10, 10, 316 - m.elec_voltage(3))
        lcd.show()
        pyb.delay(50)
async def main():
	leds = [pyb.LED(i) for i in range(1,4)]

	#tune=RTTTL('14:d=4,o=6,b=180:c,e,g')
	#buzzer.play(tune)

	n = 0
	x = y = 0
	dx = dy = 4
	lcd=pyb.LCD()
	lcd.fill(0,0,lcdWidth,lcdHeight,0x841f)                 
	lcd.text("Hello STEMBot 2!", 100, 100, 0xf800)

	 
	while True:

		# update the dot's position
		x += dx
		y += dy

		# make the dot bounce of the edges of the screen
		if x <= 0 or x > 320-2: dx = -dx
		if y <= 0 or y > 240-2: dy = -dy

		lcd.pixel(x, y, 0xfc1f)          # draw the dot
		lcd.pixel(x+1, y, 0xfc1f)          # draw the dot
		lcd.pixel(x, y+1, 0xfc1f)          # draw the dot
		lcd.pixel(x+1, y+1, 0xfc1f)          # draw the dot
	 
		n = (n + 1) % 3
		leds[n].toggle()
		await asyncio.sleep_ms(50) # pause for 50ms
		
		lcd.pixel(x, y, 0xf800)          # erase the dot
		lcd.pixel(x+1, y, 0xf800)          # erase the dot
		lcd.pixel(x, y+1, 0xf800)          # erase the dot
		lcd.pixel(x+1, y+1, 0xf800)          # erase the dot
Exemple #3
0
import pyb
import math
led3 = pyb.LED(3)
led3.on()

lcd = pyb.LCD('X')  # if pyskin is in the X position
lcd.light(True)
lcd.write('MyoGen 1.0 beta\n\nPress USR buttonto begin workout\n')

i2c = pyb.I2C(1, pyb.I2C.MASTER)
i2c.mem_write(4, 90, 0x5e)
touch = i2c.mem_read(1, 90, 0)[0]

sw = pyb.Switch()  # USR button
while True:  # wait for user to press button
    pyb.delay(100)
    led3.toggle()
    if sw():
        break
led3.on()
pyb.delay(2000)

adc = pyb.ADC(pyb.Pin.board.Y12)  # create an ADC on pin X19
buf = bytearray(100)  # create a buffer of 100 bytes

led2 = pyb.LED(2)  #green
led2.on()

accel = pyb.Accel()  # accellerometer

f = open('log/data' + str(pyb.millis()) + '.dat',
Exemple #4
0
import pyb

# Touch keypad
import mpr121
keybd = mpr121.MPR121(pyb.I2C(1, pyb.I2C.MASTER))
keybd.debounce(3,3)
for electr in range(4):
    keybd.threshold(electr, 50, 30)

# LCD
lcd = pyb.LCD('X')
lcd.light(True)

# Maths required for calculations
from math import cos, sin, pi, sqrt, atan2, asin, acos
d2r = pi/180

def circle_intersection(circle1, circle2):
    '''
    @summary: calculates intersection points of two circles
    @param circle1: tuple(x,y,radius)
    @param circle2: tuple(x,y,radius)
    @result: tuple of intersection points (which are (x,y) tuple)
    '''
    # return self.circle_intersection_sympy(circle1,circle2)
    x1,y1,r1 = circle1
    x2,y2,r2 = circle2
    # http://stackoverflow.com/a/3349134/798588
    dx,dy = x2-x1,y2-y1
    d = sqrt(dx*dx+dy*dy)
    if d > r1+r2:
Exemple #5
0
#import essential libraries
import pyb

lcd = pyb.LCD('x')
lcd.light(1)


# do 1 iteration of Conway's Game of Life
def conway_step():
    for x in range(128):  # loop over x coordinates
        for y in range(32):  # loop over y coordinates
            # count number of neigbours
            num_neighbours = (lcd.get(x - 1, y - 1) + lcd.get(x, y - 1) +
                              lcd.get(x + 1, y - 1) + lcd.get(x - 1, y) +
                              lcd.get(x + 1, y) + lcd.get(x + 1, y + 1) +
                              lcd.get(x, y + 1) + lcd.get(x - 1, y + 1))

            # check if the centre cell is alive or not
            self = lcd.get(x, y)

            # apply the rules of life
            if self and not (2 <= num_neighbours <= 3):
                lcd.pixel(x, y,
                          0)  # not enough, or too many neighbours: cell dies
            elif not self and num_neighbours == 3:
                lcd.pixel(
                    x, y, 1
                )  # exactly 3 neigbours around an empty cell: cell is born


# randomise the start
# 1.0 open, 0.0 closed
w_status = 1
#0 early, 1 late, 2 night, 3 manual
w_mode = 3

w_times = [[(19, 0), (8, 0)], [(19, 0), (10, 0)], [(7, 0), (14, 30)]]
#hardware
i2c = pyb.I2C(2, pyb.I2C.MASTER)
i2c.mem_write(4, 90, 0x5e)
touch = i2c.mem_read(1, 90, 0)[0]

s_up = pyb.Servo(1)
s_down = pyb.Servo(2)

lcd = pyb.LCD('Y')

rtc = pyb.RTC()

led_b = pyb.LED(1)
led_2 = pyb.LED(2)
#calibration
s_up.angle(-12)


def use_btn_w_servo(servo, duration=18000, inverse=False):
    if inverse:
        end_pos = -30
    else:
        end_pos = 30
    neut = servo.angle()
# import essential libraries
import pyb

lcd = pyb.LCD("x")
lcd.light(1)


# do 1 iteration of Conway's Game of Life
def conway_step():
    for x in range(128):  # loop over x coordinates
        for y in range(32):  # loop over y coordinates
            # count number of neighbours
            num_neighbours = (lcd.get(x - 1, y - 1) + lcd.get(x, y - 1) +
                              lcd.get(x + 1, y - 1) + lcd.get(x - 1, y) +
                              lcd.get(x + 1, y) + lcd.get(x + 1, y + 1) +
                              lcd.get(x, y + 1) + lcd.get(x - 1, y + 1))

            # check if the centre cell is alive or not
            self = lcd.get(x, y)

            # apply the rules of life
            if self and not (2 <= num_neighbours <= 3):
                lcd.pixel(x, y,
                          0)  # not enough, or too many neighbours: cell dies
            elif not self and num_neighbours == 3:
                lcd.pixel(
                    x, y, 1
                )  # exactly 3 neighbours around an empty cell: cell is born


# randomise the start
Exemple #8
0
import pyb
import time

txts = ['Hello World!', 'H\nW', 'x' * 100]

for txt in txts:
    for sp in ['X', 'Y']:
        for color in [0, 1]:
            lcd = pyb.LCD(sp)
            lcd.text(txt, 0, 0, color)
            lcd.show()
            time.sleep(1)

assert lcd.get(0, 0) == 0

lcd.light(True)  # turn the backlight on
lcd.write('Hello world!\n')  # print text to the screen

x = y = 0
dx = dy = 1
for i in range(50):
    # update the dot's position
    x += dx
    y += dy

    # make the dot bounce of the edges of the screen
    if x <= 0 or x >= 127: dx = -dx
    if y <= 0 or y >= 31: dy = -dy

    lcd.fill(0)  # clear the buffer
    lcd.pixel(x, y, 1)  # draw the dot