Exemple #1
0
    def update(self, value):
        # 取得値をテキストでも表示
        if self.w == win_w:
            lcd.font(lcd.FONT_DejaVu24, transparent=False)
        else:
            lcd.font(lcd.FONT_DejaVu18, transparent=False)

        fw, fh = lcd.fontSize()

        if value is not None:
            angle = int((value - self.tick_s) /
                        (self.tick_e - self.tick_s) * 100 - 50)
            if angle != self.prev_angle:
                # 前回取得値の針を消去
                if self.prev_angle is not None:
                    for i in range(-1, 2):
                        lcd.lineByAngle(self.center_x + i, self.center_y,
                                        int(self.h * 0.15), int(self.h * 0.42),
                                        self.prev_angle, lcd.WHITE)
                # 今回取得値の針を表示
                for i in range(-1, 2):
                    lcd.lineByAngle(self.center_x + i, self.center_y,
                                    int(self.h * 0.15), int(self.h * 0.42),
                                    angle, lcd.RED)

                if self.title != '':
                    lcd.print(self.title,
                              self.center_x - lcd.textWidth(self.title) // 2,
                              self.y + self.h - int(fh * 2.4), lcd.BLACK)
                self.prev_angle = angle

            if value != self.prev_value:
                text = self.value_format.format(value)
                lcd.print(text, self.center_x - lcd.textWidth(text) // 2,
                          self.y + self.h - int(fh * 1.2), lcd.BLACK)
                self.prev_value = value
        else:
            text = self.value_format.format(self.prev_value)
            lcd.print(text, self.center_x - lcd.textWidth(text) // 2,
                      self.y + self.h - int(fh * 1.2), lcd.RED)
Exemple #2
0
    def __init__(self, x, y, w, h, tick_s, tick_e, color, title, value_format):
        self.x = x  # メーターの表示位置
        self.y = y  # メーターの表示位置
        self.w = w  # メーターの表示幅
        self.h = h  # メーターの表示高
        self.tick_s = tick_s  # 目盛の最小値
        self.tick_e = tick_e  # 目盛の最大値
        self.title = title
        self.value_format = value_format  # 値をテキスト表示する際のフォーマット

        self.center_x = x + w // 2  # 針の原点
        self.center_y = y + int(h * 0.9)  # 針の原点
        self.prev_value = tick_s
        self.prev_angle = None

        lcd.roundrect(x, y, w, h, h // 10, lcd.BLACK, lcd.WHITE)
        lcd.arc(self.center_x, self.center_y, int(h * 0.67), int(h * 0.07),
                -50, 50, color, color)
        lcd.arc(self.center_x, self.center_y, int(h * 0.6), 2, -50, 50,
                lcd.BLACK)

        # 目盛の値表示用フォント設定
        if self.w == win_w:
            lcd.font(lcd.FONT_Default, transparent=False)
        else:
            lcd.font(lcd.FONT_DefaultSmall, transparent=True)

        fw, fh = lcd.fontSize()

        tick = tick_s
        tick_i = (tick_e - tick_s) // 4
        for r in range(-50, 51, 5):
            if r % 25 == 0:
                # 目盛の最小値から最大値を4分割して目盛値を表示
                lcd.lineByAngle(self.center_x - 1, self.center_y, int(h * 0.6),
                                int(h * 0.1), r, lcd.BLACK)
                lcd.lineByAngle(self.center_x, self.center_y, int(h * 0.6),
                                int(h * 0.1), r, lcd.BLACK)
                tick_text = str(tick)
                text_width = lcd.textWidth(tick_text)
                lcd.print(
                    tick_text, self.center_x +
                    int(math.sin(math.radians(r)) * h * 0.7) - text_width // 2,
                    self.center_y - int(math.cos(math.radians(r)) * h * 0.7) -
                    fh, lcd.BLACK)
                tick += tick_i
            else:
                # 細かい目盛線を表示
                lcd.lineByAngle(self.center_x, self.center_y, int(h * 0.6),
                                int(h * 0.05), r, lcd.BLACK)
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) 

Exemple #4
0
def printResult():
    lcd.clear()
    lcd.print('Date: ' + timestamp[0], 10, 10)
    lcd.print('Blue = Destination, Red = North', 10, 20)
    # lcd.print(
    #     'Location: ' + str(current_coord[0]) + ', ' + str(current_coord[1]), 10,
    #     30)
    # lcd.print("Azimuth Arg: {}".format(azimuth_arg), 10, 50)
    # lcd.print("Azimuth: {}".format(azimuth), 10, 70)

    rad = calcTargetRadian(current_coord, target_coords)
    # lcd.print("Rad: {}".format(rad), 10, 90)
    # lcd.print("Target Rad: {}".format(str((rad + azimuth) % 360)), 10, 110)
    lcd.lineByAngle(161, 119, 0, 120, round(azimuth), lcd.RED)
    lcd.lineByAngle(160, 120, 0, 120, round(azimuth), lcd.RED)
    lcd.lineByAngle(161, 121, 0, 120, round(azimuth), lcd.RED)

    lcd.lineByAngle(161, 119, 0, 120, round(rad + azimuth) % 360, lcd.BLUE)
    lcd.lineByAngle(160, 120, 0, 120, round(rad + azimuth) % 360, lcd.BLUE)
    lcd.lineByAngle(161, 121, 0, 120, round(rad + azimuth) % 360, lcd.BLUE)

    print('Date: ' + timestamp[0])
    print('Location: ' + str(current_coord[0]) + ', ' + str(current_coord[1]))
    print("Azimuth Arg: {}".format(azimuth_arg))
    print("Azimuth: {}".format(azimuth))
    print("Rad: {}".format(rad))
    print("Target Rad: {}".format(str((rad + azimuth) % 360)))