Exemplo n.º 1
0
def game_start():
	lcd.font(lcd.FONT_DejaVu18)
	GAME_RUNNING = True
	HEALTH = 10
	bird = [80,20,0,0,15] # y,x,vy,vx,r
	blns = [[80,-10,0,-1,15,lcd.BLUE],[40,-10,0.2,-0.5,10,lcd.GREEN]] # y,x,vy,vx,r,color
	GRAV = -1
	lastbtn = False
	while GAME_RUNNING:
		if HEALTH < 1: break
		if buttonA.isPressed() and not lastbtn: bird[2] += 15
		lastbtn = buttonA.isPressed()
		bird[2] += GRAV
		bird[2] *= 0.9
		bird[0] += bird[2]
		bird[0] = min(max(bird[4], bird[0]), 160-bird[4])
		lcd.clear()
		lcd.fillCircle(int(bird[0]), bird[1], bird[4], lcd.RED)
		lcd.fillCircle(int(bird[0])+6, bird[1]+2, 3, lcd.WHITE)
		lcd.fillCircle(int(bird[0])+6, bird[1]+10, 3, lcd.WHITE)
		lcd.fillCircle(int(bird[0])+6, bird[1]+2, 1, lcd.BLACK)
		lcd.fillCircle(int(bird[0])+6, bird[1]+10, 1, lcd.BLACK)
		lcd.fillTriangle(int(bird[0])-5, bird[1]+13, int(bird[0])-10, bird[1]+3, int(bird[0]), bird[1]+3, lcd.YELLOW)
		for b in blns:
			if b[1] < -b[4]:
				b[1] = 80+b[4]
				b[0] = randint(20,140)
				b[2] = (randint(0,10)-5)/5.0
				b[3] = -randint(5,10)/5.0
				b[4] = randint(5,15)
				b[5] = getrandbits(24)
			b[0] += b[2]
			b[1] += b[3]
			if((b[0]-bird[0])**2 + (b[1]-bird[1])**2 < (bird[4]+b[4])**2):
				HEALTH -= 1
				b[1] = -100
				tone([(440, 100)])
			lcd.line(int(b[0]),int(b[1]),int(b[0])-(4*b[4]),int(b[1]),lcd.WHITE)
			lcd.fillCircle(int(b[0]),int(b[1]),b[4],b[5])
		lcd.print(str(HEALTH)+" <3",140,0,lcd.WHITE,rotate=90)
		sleep_ms(30)
	
	lcd.setTextColor(lcd.WHITE)
	lcd.text(40,0,"GAME")
	lcd.text(20,0,"OVER")
	sleep_ms(700)
	tone(TONE_DENY)
	reset()
Exemplo n.º 2
0
def loop():
  global ison
  while True:
    if buttonA.isPressed():
      ison = True
    if buttonB.isPressed():
      minmax()
    if buttonC.isPressed():
      ison = False
    if ison:
      graph()
Exemplo n.º 3
0
def loop():
    global ison
    while True:
        if buttonA.isPressed():
            ison = True
        if buttonB.isPressed():
            minmax()
        if buttonC.isPressed():
            ison = False
        if ison:
            graph()
Exemplo n.º 4
0
def fingerDENYCb():
	global IGNORE_FINGER
	if IGNORE_FINGER: return
	GAME_RUNNING = False
	clrscrn()
	lcd.print("Unknown  :(\nFinger")
	tone(TONE_DENY)
	sleep_ms(1000)
	clrscrn()
	lcd.setTextColor(lcd.MAGENTA)
	lcd.print("Hold button\nto skip\nthe game")
	sleep_ms(2000)
	if buttonA.isPressed(): mainScrn()
	else: game_start()
Exemplo n.º 5
0
def main():
	from m5stack import lcd, buttonA
	import network
	import json
	import time

	try:
		isConnected = False
		lcd.setCursor(0,0)
		sta_if = network.WLAN(network.STA_IF)
		if sta_if.active() == False:
			lcd.println('Connecting...')
			sta_if.active(True)
			wifi = json.load(open('/flash/etc/wlan.json', 'r'))
			ssid = wifi['wifi']['ssid']
			pwd = wifi['wifi']['password']
			sta_if.connect(ssid, pwd)
			# time.sleep(3)

		while not buttonA.isPressed():
			ni = sta_if.ifconfig()
			if ni[0] == '0.0.0.0':
				time.sleep(1)
			else:
				isConnected = True
				lcd.println('ip: %s' % ni[0])
				lcd.println('mask: %s' % ni[1])
				lcd.println('gate: %s' % ni[2])
				lcd.println('dns: %s' % ni[3])
				break

		if isConnected:
			while not buttonA.isPressed():
				time.sleep(.2)
	except:
		pass
Exemplo n.º 6
0
    def app_txtReader(self, fname):
        lcd.clear()
        f = Framework('txtReader')
        f.drawNaviButton(strC='EXIT')
        lcd.font(lcd.FONT_DefaultSmall, transparent=False, fixedwidth=True)
        idx = 0
        idx_s = [0]
        page = 0
        while True:
            letter_current_page = 0
            lcd.setCursor(0, 0)
            lcd.rect(0, 0, 320, 240 - f.h_bottom, lcd.BLACK, lcd.BLACK)
            with open(fname, 'r') as o:
                o.seek(idx)
                flag_end = False

                for row in range(20):
                    for col in range(29):
                        c = o.read(1)
                        if not c:
                            lcd.println('--- END ---')
                            flag_end = True
                            break
                        if c != '\n':
                            lcd.print(c)
                            letter_current_page += 1
                        else:
                            letter_current_page += 1
                            break
                    lcd.print('\n')
                    if flag_end:
                        break
            while True:
                time.sleep(0.1)
                if buttonA.isPressed():
                    if page != 0:
                        page -= 1
                        del (idx_s[-1])
                        idx = idx_s[-1]
                        break
                elif buttonB.isPressed():
                    if c:
                        idx += letter_current_page
                        idx_s.append(idx)
                        page += 1
                        break
                elif buttonC.isPressed():
                    return 0
Exemplo n.º 7
0
def main():
    from m5stack import lcd, buttonA
    from mpu9250 import MPU9250
    from time import sleep_ms
    from machine import I2C
    import network
    
	# lcd.font(lcd.FONT_Small, transparent=True, fixedwidth=False)

    try:
        sta_if = network.WLAN(network.STA_IF)
        if sta_if.active() == True:
            m_acc = network.mqtt('acc', 'mqtt://srdmobilex.ddns.net', port=65530, clientid='a')
            m_gyro = network.mqtt('gyro', 'mqtt://srdmobilex.ddns.net', port=65530, clientid='g')
            m_acc.start()
            m_gyro.start()
            m_acc.subscribe('acc', 2)
            m_gyro.subscribe('gyro', 0)

        i2c = I2C(sda = 21, scl = 22)
        
        imu = MPU9250(i2c)

        lcd.clear()
        lcd.setColor(lcd.WHITE)
        lcd.font(lcd.FONT_Small, transparent=False)

        counter = 0

        while not buttonA.isPressed():
            accel = imu.acceleration
            gyro = imu.gyro
            mag = imu.magnetic
            lcd.print("ACCEL: {:+7.2f}  {:+7.2f}  {:+7.2f}".format(accel[0], accel[1], accel[2]), lcd.CENTER, 20)
            lcd.print("GYRO:  {:+7.2f}  {:+7.2f}  {:+7.2f}".format(gyro[0], gyro[1], gyro[2]), lcd.CENTER, 40)
            lcd.print("MAG:   {:+7.2f}  {:+7.2f}  {:+7.2f}".format(mag[0], mag[1], mag[2]), lcd.CENTER, 60)
            if sta_if.active() == True:
                m_acc.publish('acc', '{:+7.2f},{:+7.2f},{:+7.2f}'.format(accel[0], accel[1], accel[2]) + '(%d)'%counter)
                m_gyro.publish('gyro', '{:+7.2f}  {:+7.2f}  {:+7.2f}'.format(gyro[0], gyro[1], gyro[2]) + '(%d)'%counter)
                counter += 1
            sleep_ms(20)

        m_acc.free()
        m_gyro.free()
        i2c.deinit()
        lcd.print('Exit.', 0, 100)
    except:
        return -1
Exemplo n.º 8
0
	def run(self):
		if self.fileCheck() < 0:
			return -1
		self.drawNaviButton()
		
		lcd.setCursor(0,0)
		lcd.println('Press START to start')
		while not buttonA.isPressed():
			if buttonC.isPressed():
				return 0
			time.sleep(.5)

		self.fname_save = self.fnameGen()
		lcd.println('Record into %s' % self.fname_save)

		self.scanner()
Exemplo n.º 9
0
def main():
	import network
	from m5stack import lcd, buttonA
	import time

	try:
		while not buttonA.isPressed():
			lcd.setCursor(0, 0)
			network.ftp.start(user="******", password="******", buffsize=1024, timeout=300)
			fs = network.ftp.status()
			lcd.println('Server IP: %s' % fs[4])
			lcd.println('Server status: %s' % fs[2])
			lcd.println('Data status: %s' % fs[3])
			time.sleep(1)
		network.ftp.stop()
	except:
		pass
Exemplo n.º 10
0
def main():
    from m5stack import lcd, buttonA
    import time, machine
    try:
        rtc = machine.RTC()
        print("Synchronize time from NTP server ...")
        # lcd.println("Synchronize time from NTP server ...")
        rtc.ntp_sync(server="cn.ntp.org.cn")

        lcd.font(lcd.FONT_7seg, fixedwidth=True, dist=16, width=2)

        while not buttonA.isPressed():
            d = time.strftime("%Y-%m-%d", time.localtime())
            t = time.strftime("%H:%M:%S", time.localtime())
            lcd.print(d, lcd.CENTER, 50, lcd.ORANGE)
            lcd.print(t, lcd.CENTER, 130, lcd.ORANGE)
            time.sleep(1)
    except:
        pass
def clock():
    rtc = machine.RTC()
    print("Synchronize time from NTP server ...")
    lcd.println("Synchronize time from NTP server ...")
    rtc.ntp_sync(
        server="ru.pool.ntp.org",
        tz="CET-3CEST,M3.5.0,M10.5.0/3")  # Часовой пояс меняется в CET-3CEST
    lcd.clear(lcd.BLUE)
    lcd.setColor(lcd.BLACK, lcd.BLUE)
    lcd.font(lcd.FONT_Comic, fixedwidth=True, dist=16, width=2)
    while True:
        d = time.strftime("%d-%m-%Y", time.localtime())
        t = time.strftime("%H:%M:%S", time.localtime())
        lcd.print(d, lcd.CENTER, 50)
        lcd.print(t, lcd.CENTER, 130)
        time.sleep(0.02)
        if buttonA.isPressed():
            break
        if buttonС.isPressed():
            break
Exemplo n.º 12
0
def main():
    from m5stack import lcd, buttonA
    from alib.mpu6050 import MPU6050
    from time import sleep_ms
    from machine import I2C

    
    # lcd.font(lcd.FONT_Small, transparent=True, fixedwidth=False)
    i2c = I2C(sda = 21, scl = 22, speed=400000)

    try:
        # lcd.println('I2C port has been used.')
        
        imu = MPU6050(i2c)

        lcd.clear()
        lcd.setColor(lcd.WHITE)
        lcd.font(lcd.FONT_Small, transparent=False)

        while not buttonA.isPressed():
            accel = imu.acceleration
            gyro = imu.gyro
            # mag = imu.magnetic
            # print("ACCEL:  {:8.3f}   {:8.3f}   {:8.3f}".format(accel[0], accel[1], accel[2]))
            # print("GYRO:   {:8.3f}   {:8.3f}   {:8.3f}".format(gyro[0], gyro[1], gyro[2]))
            # print("MAG:    {:8.3f}   {:8.3f}   {:8.3f}".format(mag[0], mag[1], mag[2]))
            # print('')
            lcd.print("ACCEL: {:+7.2f}  {:+7.2f}  {:+7.2f}".format(accel[0], accel[1], accel[2]), lcd.CENTER, 20)
            lcd.print("GYRO:  {:+7.2f}  {:+7.2f}  {:+7.2f}".format(gyro[0], gyro[1], gyro[2]), lcd.CENTER, 40)
            # lcd.print("MAG:   {:+7.2f}  {:+7.2f}  {:+7.2f}".format(mag[0], mag[1], mag[2]), lcd.CENTER, 60)
            sleep_ms(10)

        lcd.print('Exit.', 0, 100)
    except:
        print('ERR')
    i2c.deinit()
Exemplo n.º 13
0
from m5stack import lcd, buttonA, buttonB
from machine import Pin
import utime as time
from mpu9250 import MPU9250
from fusion import Fusion
from machine import I2C

i2c = I2C(sda = 21, scl = 22)
imu = MPU9250(i2c)
fuse = Fusion()


def getmag():                               # Return (x, y, z) tuple (blocking read)
    return imu.mag.xyz

if buttonA.isPressed():
    print("Calibrating. Press switch when done.")
    fuse.calibrate(getmag, BtnB.press, lambda : time.sleep(0.1))
    print(fuse.magbias)

if False:
    mag = imu.magnetic # Don't include blocking read in time
    accel = imu.acceleration # or i2c
    gyro = imu.gyro
    start = time.ticks_us()  # Measure computation time only
    fuse.update(accel, gyro, mag) # 1.97mS on Pyboard
    t = time.ticks_diff(time.ticks_us(), start)
    print("Update time (uS):", t)


lcd.clear()
Exemplo n.º 14
0
 def alert(self, text):
     lcd.rect(0, 0, 320, 240, lcd.DARKGREY, lcd.DARKGREY)
     lcd.println(text, lcd.CENTER, color=lcd.RED)
     lcd.println('Long press \"A\" to exit', lcd.CENTER, color=lcd.BLACK)
     while not buttonA.isPressed():
         time.sleep(1)
Exemplo n.º 15
0
def main():
    import time
    import uos

    from m5stack import lcd, buttonA, buttonB, buttonC
    import network
    import binascii

    DNAME_ROOT = 'wifi_analyzer'

    def drawNaviButton(strA='START', strB='STOP', strC='EXIT'):
        lcd.text(40, 215, strA, lcd.WHITE)
        lcd.text(135, 215, strB, lcd.WHITE)
        lcd.text(240, 215, strC, lcd.WHITE)

    def fnameGen():
        currentFileList = list(
            filter(lambda x: 'WA_' in x, uos.listdir('/sd/' + DNAME_ROOT)))
        currentFileList = list(map(lambda x: x.lower(), currentFileList))
        if 'wa_0001.csv' not in currentFileList:
            return 'WA_0001.csv'
        else:
            currentFileList.sort()
            newestFileName = currentFileList[-1]
            no = int(newestFileName[3:7])
            return 'WA_%s.csv' % (('%4d' % (no + 1)).replace(' ', '0'))

    def resdisplay(apresults, n, time):
        lcd.rect(0, 0, 320, 24, lcd.BLUE, lcd.BLUE)
        lcd.font(lcd.FONT_Ubuntu, transparent=True)
        lcd.text(0, 2, 'N_AP:%d N_SCAN:%d TIME:%d' % (len(apresults), n, time),
                 lcd.WHITE)
        lcd.rect(0, 24, 320, 186, lcd.BLACK, lcd.BLACK)
        lcd.setCursor(0, 24)
        lcd.font(lcd.FONT_DefaultSmall)

        if len(apresults) < 15:
            i = 0
            for apresult in apresults:
                resstr = '%02d, ch: %02d, rs: %d, %s\n' % (
                    i + 1, apresult[2], apresult[3], apresult[0].decode())
                lcd.print(resstr, color=lcd.WHITE)
                i = i + 1
        else:
            for i in range(0, 15):
                apresult = apresults[i]
                resstr = '%02d, ch: %02d, rs: %d, %s\n' % (
                    i + 1, apresult[2], apresult[3], apresult[0].decode())
                lcd.print(resstr, color=lcd.WHITE)

    try:
        uos.stat('/sd')
    except:
        try:
            uos.mountsd()
        except:
            lcd.println('No SD card is found.')
            return -1

    try:
        sdFiles = uos.listdir('/sd')
        if DNAME_ROOT not in sdFiles:
            uos.mkdir('/sd/' + DNAME_ROOT)
    except:
        lcd.println('The SD card is not writable.')
        return -2

    try:
        drawNaviButton()
        lcd.setCursor(0, 0)

        lcd.println('Press START to start')
        while not buttonA.isPressed():
            time.sleep(.5)
            if buttonC.isPressed():
                return 0

        wlan = network.WLAN(network.STA_IF)
        wlan.active(True)

        fname = fnameGen()
        lcd.println('Recording into %s...' % fname)

        ts = time.time()
        n = 0
        while not buttonB.isPressed():
            buf = ''
            aps = wlan.scan()
            n += 1
            te = time.time() - ts
            for ap in aps:
                # (ssid, bssid, primary_chan, rssi, auth_mode, auth_mode_string, hidden)
                mac = (binascii.hexlify(ap[1])).decode()
                mac = ':'.join([
                    mac[:2], mac[2:4], mac[4:6], mac[6:8], mac[8:10],
                    mac[10:12]
                ])
                buf += '%.3f,%s,%s,%d,%s\n' % (te, mac, ap[0].decode(), ap[3],
                                               ap[2])
            print(buf + '---------------------')
            resdisplay(aps, n, int(te))

            with open('/sd/' + DNAME_ROOT + '/' + fname, 'a') as o:
                o.write(buf)
        lcd.println('Exit.')

    except:
        print('Exit since error.')
        pass
Exemplo n.º 16
0
 def run(self):
     self.mqtt()
     while not buttonA.isPressed():
         time.sleep(.2)