コード例 #1
0
ファイル: LCD_demo.py プロジェクト: saimaza123/smartdevice
def lineDemo(sec=5):

    header("LINE DEMO", True)

    n = time.time() + sec

    while time.time() < n:

        x1 = machine.random(maxx - 4)

        y1 = machine.random(miny, maxy - 4)

        x2 = machine.random(maxx - 1)

        y2 = machine.random(miny, maxy - 1)

        color = machine.random(0xFFFFFF)

        lcd.line(x1, y1, x2, y2, color)

        if btnA.wasPressed():
            speaker.tone(346, 120, 1)
            break

    lcd.resetwin()
コード例 #2
0
 def drawNaviButton(self, strA='UP', strB='DOWN', strC='SELECT'):
     lcd.rect(0, self.H - self.h_bottom, self.W, self.h_bottom,
              lcd.DARKGREY, lcd.DARKGREY)
     lcd.line(int(self.W / 3), self.H - self.h_bottom, int(self.W / 3),
              self.H, lcd.WHITE)
     lcd.line(int(2 * self.W / 3), self.H - self.h_bottom,
              int(2 * self.W / 3), self.H, lcd.WHITE)
     lcd.text(40, 215, strA, lcd.WHITE)
     lcd.text(135, 215, strB, lcd.WHITE)
     lcd.text(240, 215, strC, lcd.WHITE)
コード例 #3
0
    def _draw_once(self):
        '''最初に一度だけ描画する処理'''
        # 枠を表示 (デバッグ用)
        #lcd.rect(0, 0, self.width + 1, self.height + 1, lcd.BLACK)

        # 温度計の液溜め部分(正式には「球部」)の円を描画
        lcd.circle(self.circle_x, self.circle_y, self.circle_radius,
                   self.color, self.color)

        # 目盛りの間隔 (摂氏度)
        tick = 10

        # 目盛りとグラフの隙間のピクセル数
        m = 2

        # 目盛りの長さ (ピクセル)
        l = 8

        # 目盛りと軸の数字の隙間のピクセル数
        m2 = 4

        # フォントの設定
        lcd.font(lcd.FONT_Default, color=self.axis_color, transparent=True)

        # TODO: ラベルを描画
        label_x = self.bar_x - m - l - m2 - lcd.textWidth(self.label)
        label_y = self.y
        lcd.text(label_x, label_y, self.label)

        # フォントの設定
        lcd.font(lcd.FONT_Default, color=self.axis_color, transparent=True)

        # フォントサイズ
        font_width, font_height = lcd.fontSize()
        half_font_height = int(round(font_height / 2))

        min_ylabel = int(math.ceil(self.min_value / 10)) * 10
        for i in range(min_ylabel, self.max_value + 1, tick):
            y1 = self._calc_y(i)

            # 目盛り (左)
            lcd.line(self.bar_x - m - l, y1, self.bar_x - m, y1,
                     self.axis_color)

            # 目盛り (右)
            lcd.line(self.bar_x + self.bar_width + m, y1,
                     self.bar_x + self.bar_width + m + l, y1, self.axis_color)

            # 目盛りラベル
            tick_label = '{}'.format(i)
            lcd.print(tick_label,
                      self.bar_x - m - l - m2 - lcd.textWidth(tick_label),
                      y1 - half_font_height, self.axis_color)
コード例 #4
0
def drawChart(buff):
    tmp = tuple(map(sorted, zip(*buff)))
    minT = int(tmp[0][0]) - 1
    maxT = int(tmp[0][-1]) + 1
    minH = int(tmp[1][0]) - 10
    maxH = int(tmp[1][-1]) + 10
    for i in range(len(buff) - 1):
        lcd.line(i * 2 + X0, th2y(buff[i][0], minT, maxT,
                                  HEIGHT), (i + 1) * 2 + X0,
                 th2y(buff[i + 1][0], minT, maxT, HEIGHT), lcd.GREEN)
        lcd.line(i * 2 + X0, th2y(buff[i][1], minH, maxH,
                                  HEIGHT), (i + 1) * 2 + X0,
                 th2y(buff[i + 1][1], minH, maxH, HEIGHT), lcd.RED)
コード例 #5
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()
コード例 #6
0
def sample(buff):
    for i in range(SAMPLE_SIZE):
        t = tm.value()
        ax, ay, az = IMU.acceleration
        buff.append(az * 100)
        gc.collect()

        if (i != 0):
            if (data2y(buff[i - 1]) != data2y(buff[i])):
                lcd.line(i - 1 + X0, data2y(buff[i - 1]), i + X0,
                         data2y(buff[i]), lcd.GREEN)
            else:
                lcd.pixel(i - 1 + X0, data2y(buff[i - 1]), lcd.GREEN)
                lcd.pixel(i + X0, data2y(buff[i]), lcd.GREEN)

        while (tm.value() - t) < SAMPLE_PERIOD:
            pass
コード例 #7
0
    def printToLcd(self):
        if self._coord == None:
            self._coord = lcd.getCursor()

        oldTxt = self._format.format(self._oldValue) + self._suffix
        oldTxtWidth = lcd.textWidth(oldTxt)
        txt = self._format.format(self.value) + self._suffix
        txtWidth = lcd.textWidth(txt)
        # erase
        lcd.textClear(self._coord[0], self._coord[1], oldTxt, lcd.WHITE)
        lcd.line(self._coord[0], self._coord[1] + 25,
                 self._coord[0] + oldTxtWidth, self._coord[1] + 25, lcd.WHITE)

        # write
        lcd.setCursor(self._coord[0], self._coord[1])
        lcd.print(txt)
        if self._editingActive:
            lcd.line(self._coord[0], self._coord[1] + 25,
                     self._coord[0] + txtWidth, self._coord[1] + 25)
コード例 #8
0
    def printToLcd(self):
        if self._coord == None:
            self._coord = lcd.getCursor()

        oldTxt = self._oldValue
        oldTxtWith = lcd.textWidth(oldTxt)
        txt = self.value
        txtWidth = lcd.textWidth(txt)
        # erase
        lcd.textClear(self._coord[0], self._coord[1], oldTxt, lcd.WHITE)
        lcd.line(self._coord[0], self._coord[1] + 25,
                 self._coord[0] + oldTxtWith, self._coord[1] + 25, lcd.WHITE)

        # write
        x = (320 - (lcd.textWidth(self.value))) / 2
        lcd.setCursor(int(x), self._coord[1])
        self._coord = lcd.getCursor()
        lcd.print(txt)
        if self._editingActive:
            lcd.line(self._coord[0], self._coord[1] + 25,
                     self._coord[0] + txtWidth, self._coord[1] + 25)
コード例 #9
0
from m5stack import lcd

# LCD

# setup
lcd.clear(0xC70039)
lcd.fill(0x222222)

# lcd.arc(0, 0, 10, 30, 40, 0)
lcd.circle(290, 150, 20)
lcd.ellipse(260, 50, 10, 10) #comment
# lcd.font(lcd.FONT_Comic) // not working
# fontSize = lcd.fontSize(); // not working
lcd.line(10, 100, 50, 40)
lcd.lineByAngle(100, 100, 5, 50, 180)
lcd.pixel(200, 200, 0xAABBFF)
# lcd.polygon(10, 10, 30, 30, 10)
# comment
lcd.print('hello world', 130, 50)
lcd.rect(50, 100, 150, 100, 0xEEFFFF)
lcd.triangle(200, 0, 10, 20, 50, 80, 0xFFFFFF) 

            ya = cube[i][1]
            z1 = cube[i][2] * cos(r) - cube[i][0] * sin(r)
            x2 = x1
            y2 = ya * cos(r) - z1 * sin(r)  # rotate X
            z2 = ya * sin(r) + z1 * cos(r)
            x3 = x2 * cos(r) - y2 * sin(r)  # rotate Z
            y3 = x2 * sin(r) + y2 * cos(r)
            z3 = z2
            x3 = x3 + X
            y3 = y3 + Y
            f[i][0] = x3  # store new values
            f[i][1] = y3
            f[i][2] = z3

        lcd.clear(lcd.BLUE)  # clear
        lcd.line(int(f[0][0]), int(f[0][1]), int(f[1][0]), int(f[1][1]), 1)
        lcd.line(int(f[1][0]), int(f[1][1]), int(f[2][0]), int(f[2][1]), 1)
        lcd.line(int(f[2][0]), int(f[2][1]), int(f[3][0]), int(f[3][1]), 1)
        lcd.line(int(f[3][0]), int(f[3][1]), int(f[0][0]), int(f[0][1]), 1)
        lcd.line(int(f[4][0]), int(f[4][1]), int(f[5][0]), int(f[5][1]), 1)
        lcd.line(int(f[5][0]), int(f[5][1]), int(f[6][0]), int(f[6][1]), 1)
        lcd.line(int(f[6][0]), int(f[6][1]), int(f[7][0]), int(f[7][1]), 1)
        lcd.line(int(f[7][0]), int(f[7][1]), int(f[4][0]), int(f[4][1]), 1)
        lcd.line(int(f[0][0]), int(f[0][1]), int(f[4][0]), int(f[4][1]), 1)
        lcd.line(int(f[1][0]), int(f[1][1]), int(f[5][0]), int(f[5][1]), 1)
        lcd.line(int(f[2][0]), int(f[2][1]), int(f[6][0]), int(f[6][1]), 1)
        lcd.line(int(f[3][0]), int(f[3][1]), int(f[7][0]), int(f[7][1]), 1)
        lcd.line(int(f[1][0]), int(f[1][1]), int(f[3][0]), int(f[3][1]), 1)
        lcd.line(int(f[0][0]), int(f[0][1]), int(f[2][0]), int(f[2][1]), 1)
        sleep_ms(3)
コード例 #11
0
ファイル: main.py プロジェクト: key/playground-m5stack
from machine import I2C
from mpu9250 import MPU9250
import time

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

lcd.clear()

x, y = 0, 0

while True:
    ax, ay, az = sensor.acceleration
    ax = ax * -1  # original is left negative

    # clear previous ball
    lcd.circle(x, y, 5, lcd.BLACK, lcd.BLACK)

    # g-bowl
    lcd.circle(160, 120, 110, lcd.WHITE)
    lcd.circle(160, 120, 55, lcd.WHITE)
    lcd.line(50, 120, 270, 120, lcd.WHITE)
    lcd.line(160, 10, 160, 230, lcd.WHITE)

    # plot ball
    x = int(ax * (55 / 10)) + 160
    y = int(ay * (55 / 10)) + 120
    lcd.circle(x, y, 5, lcd.RED, lcd.RED)

    time.sleep_ms(20)