Пример #1
0
def handler(ch, event):
     global Clock
     global Backlight
     global Volume
     if event == 'press':
        if (ch == 0) and Volume<6:
            Volume=Volume+1
        if (ch == 2) and Volume>0:
            Volume=Volume-1
        if (ch == 1):
            Clock = not Clock
            Time()
        if ((ch == 4) and (Backlight==False)):
            Backlight=True
            backlight.set_all(0,0,0)
        else:
            if ((ch == 4) and (Backlight==True)): 
                Backlight=False
                backlight.set_all(random.randint(0,255),random.randint(0,255),random.randint(0,255))
        for x in range(2,7):
           for y in range(56,8,-1):
               lcd.set_pixel(x, y, 0)
        for x in range(2,6):
           for y in range(56,int(56-(8*Volume)),-1):
               lcd.set_pixel(x+(y  % 2), y, x % 2)
        backlight.show()
        lcd.show()
Пример #2
0
def drawHorizontalLine(y):
    from gfxhat import lcd, backlight
    from time import sleep
    from rios0021Library import clearBacklight
    # Clear the lcd
    lcd.clear()
    lcd.show()
    # Clear backlight
    clearBacklight()
    r = 255
    g = 0
    # Draw the line at y
    for x in range(0, 128):
        lcd.set_pixel(x, y, 1)
        lcd.show()
        # Additional code to make a color transition while drawing line
        backlight.set_all(r, g, 0)
        backlight.show()
        if (g < 252):
            g += 4
        elif (r > 3):
            r -= 4
    # Turn off backlight after 2 seconds
    sleep(2)
    clearBacklight()
    lcd.clear()
    lcd.show()
Пример #3
0
def Time():
    global Stop
    global ImagePng
    date=datetime.now()
    if Stop==True:
      return 0
    time = os.popen("date +%R").readline()
    font = ImageFont.truetype(fonts.FredokaOne, 26)
    width, height = lcd.dimensions()
    spritemap = Image.open("/boot/TriggerBot-master/Peka.png").convert("PA")
    image = Image.new('1', (width, height),"black")
    image.paste(spritemap,(width-32,33))
    draw = ImageDraw.Draw(image)
    draw.line([(32,8),(96,8)],fill ="white",width=1)
    draw.line([(32,8),(64,56)],fill ="white",width=1)
    draw.line([(96,8),(64,56)],fill ="white",width=1)
    w, h = font.getsize(time)
    print(w,h)
    draw.text(((width-w+16)/2, 16), time,1, font=font)
    ImagePng=image
    for x in range(128):
        for y in range(64):
            pixel = image.getpixel((x, y))
            lcd.set_pixel(x, y, pixel)
    lcd.show()
    if date.hour>23 or date.hour<11:
      backlight.set_all(50,50,50)
    else:
      backlight.set_all(random.randint(0,255),random.randint(0,255),random.randint(0,255))
    backlight.show()
Пример #4
0
def staircase(w, h):
    lcd.clear()
    lcd.show()

    x = 15
    y = 8

    while x >= 0 and x <= 127 and y >= 0 and y <= 63:
        a = 0
        b = 0

        for a in range(0, w):
            lcd.set_pixel(x, y, 1)
            x = x + 1
            if a == w - 1 or x == 127:
                break

        for b in range(0, h):
            lcd.set_pixel(x, y, 1)
            y = y + 1
            if b == h - 1 or y == 127:
                break

    backlight.set_all(0, 255, 0)
    backlight.show()
    lcd.show()
    return
Пример #5
0
 def cleanup(self):
     backlight.set_all(0, 0, 0)
     backlight.show()
     lcd.clear()
     lcd.show()
     for i in range(0, self.num_leds):
         touch.set_led(i, 0)
Пример #6
0
def displayIpOnGFX():
    led_states = [False for _ in range(6)]
    width, height = lcd.dimensions()
    image = Image.new('P', (width, height))
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype(fonts.AmaticSCBold, 22)
    text = getMyIp()

    w, h = font.getsize(text)
    x = (width - w) // 2
    y = (height - h) // 2

    draw.text((x, y), text, 1, font)

    backlight.set_all(120, 120, 120)

    backlight.show()

    for x in range(128):
        for y in range(64):
            pixel = image.getpixel((x, y))
            lcd.set_pixel(x, y, pixel)

    lcd.show()
    time.sleep(10)
    #	input('< Hit a key >')
    lcd.clear()
    lcd.show()
    backlight.set_all(0, 0, 0)
    backlight.show()
Пример #7
0
 def off(self):
     for x in range(6):
         backlight.set_all(0, 0, 0)
         touch.set_led(x, 0)
     backlight.show()
     lcd.clear()
     lcd.show()
Пример #8
0
def displayObject(obj,x,y):
    backlight.set_all(240,230,200)
    backlight.show()
    for row in range(y,len(obj)+y):
        for column in range(x,len(obj[row-y])+x):
            lcd.set_pixel(column, row, obj[row-y][column-x])
    lcd.show()
Пример #9
0
def Msg(message: Message):
    global Clock
    global Stop
    global Count
    global ImagePng
    Count=10
    Stop=True
    Clock=False
    msg = message.text
    msg=msg.replace("/msg ", '')
    font = ImageFont.truetype("/boot/TriggerBot-master/CCFONT.ttf", 12)
    width, height = lcd.dimensions()
    spritemap = Image.open("/boot/TriggerBot-master/Peka.png").convert("PA")
    image = Image.new('1', (width, height),"black")
    image.paste(spritemap,(width-32,33))
    draw = ImageDraw.Draw(image)
    lines = textwrap.wrap(msg, width=16)
    y_text = 16
    for line in lines:
        w, h = font.getsize(line)
        draw.text(((width-w)/2, y_text), line,1, font=font)
        y_text += h
    for x in range(128):
        for y in range(64):
            pixel = image.getpixel((x, y))
            lcd.set_pixel(x, y, pixel)
    backlight.set_all(random.randint(0,255),random.randint(0,255),random.randint(0,255))
    backlight.show()
    lcd.show()
    ImagePng=image
    bot.reply_to(message, "✔�", parse_mode="Markdown")
    Stop=False
    LedOnOff()
Пример #10
0
    async def __switch_backlight_off(self):
        if(self.__debug):
            print("Switching backlight off")

        backlight.set_all(0, 0, 0)
        backlight.show()
        self.__backlight_timed_out = True
Пример #11
0
 def turn_display_off():
     for x in range(6):
         touch.set_led(x, 0)
     backlight.set_all(0, 0, 0)
     backlight.show()
     lcd.clear()
     lcd.show()
Пример #12
0
def Rainbow():
    global r
    global g
    global b

    center=128
    width=127
    Len=50
    frequency1=0.2
    frequency2=0.2
    frequency3=0.2
    phase1=0
    phase2=2
    phase3=4
    red=r
    green=g
    blue=b
    

    for i in range( Len ):
        r =math.sin(frequency1*i + phase1) * width + center
        g =math.sin(frequency2*i + phase2) * width + center
        b =math.sin(frequency3*i + phase3) * width + center
        backlight.set_all(int(r),int(g),int(b))
        backlight.show()
        time.sleep(0.1)
        
    r=red
    g=green
    b=blue
 def menu():
     backlight.set_all(255, 255, 255)
     backlight.show()
     choice = input("Enter number:    1. Draw character   2. Exit   >>> ")
     if (choice == "1"):
         characterChoice = input("Which character do you want to print? > ")
         if characterChoice in fonts.keys():
             x = int(input("Inform start position in axis X  >>> "))
             y = int(input("Inform start position in axis Y  >>> "))
             displayObject(fonts[characterChoice], x, y)
             input("Press enter to erase and go back.")
             lcd.clear()
             lcd.show()
             menu()
         else:
             print("Character not in list.")
             menu()
     if (choice == "2"):
         lcd.clear()
         backlight.set_all(0, 0, 0)
         lcd.show()
         backlight.show()
         print("Goodbye!")
     else:
         print("Invalid choice.")
         menu()
Пример #14
0
def drawVerticalLine(x):
    from gfxhat import lcd, backlight
    from time import sleep
    from rios0021Library import clearBacklight
    # Clear the lcd
    lcd.clear()
    lcd.show()
    # Clear backlight
    clearBacklight()
    g = 255
    b = 0
    # Draw the line at x
    for y in range(0, 64):
        lcd.set_pixel(x, y, 1)
        lcd.show()
        # Additional code to make a color transition while drawing line
        backlight.set_all(0, g, b)
        backlight.show()
        if (b < 248):
            b += 7
        elif (g > 5):
            g -= 10
    # Turn off backlight after 2 seconds
    sleep(2)
    clearBacklight()
    lcd.clear()
    lcd.show()
Пример #15
0
def flash():
    for i in range(0, 256, 1):
        print(i), backlight.set_all(i, 0, 0)
        time.sleep(0.001)
        backlight.show()
    for i in range(255, 0, -1):
        print(i), backlight.set_all(i, 0, 0)
        time.sleep(0.001)
        backlight.show()
Пример #16
0
 def set_backlight(self):
     try:
         self.is_playing = self.controller.get_playing_state()
         if self.is_playing:
             colour = [255, 255, 255]
         else:
             colour = [255, 0, 0]
         backlight.set_all(colour[0], colour[1], colour[2])
         backlight.show()
     except:
         print("Network Error")
Пример #17
0
def reply_on_mention(message: Message):
    global Clock
    global Stop
    global Count
    global UwUMode
    global ImagePng
    global Vocal
    if random.randint(1, 100)<15:
         Vocal=True
    Count=50
    Stop=True
    Clock=False
    user_obj: TGUserModel = get_user_from_message(message)
    group: GroupSettings = get_group_from_message(message) if message.chat.type != 'private' else None
    if(group and group.override_settings):  # Use group's settings
        settings: TGUserModel = group.user
    else:
        group = None
        settings = user_obj
    generated_message = generate_markov(fetch_messages(settings, group))
    if (generated_message and not check_duplicated(generated_message, user_obj, group)):
            if UwUMode==True:
               generated_message=generated_message.replace("l", 'w')
               generated_message=generated_message.replace("r", 'w')
            width, height = lcd.dimensions()
            spritemap = Image.open("/boot/TriggerBot-master/Peka.png").convert("PA")
            image = Image.new('1', (width, height),"black")
            image.paste(spritemap,(width-32,33))
            draw = ImageDraw.Draw(image)
            w, h = lcd.dimensions()
            font = ImageFont.truetype("/boot/TriggerBot-master/CCFONT.ttf", 12)
            lines = textwrap.wrap(generated_message, width=16)
            y_text = 0
            for line in lines:
                width, height = font.getsize(line)
                draw.text(((w- width)/4, y_text), line,1, font=font)
                y_text += height
            for x in range(128):
                for y in range(64):
                  pixel = image.getpixel((x, y))
                  lcd.set_pixel(x, y, pixel)
            backlight.set_all(random.randint(0,255),random.randint(0,255),random.randint(0,255))
            backlight.show()
            lcd.show()
            ImagePng=image
            if Vocal==False:
                bot.reply_to(message, generated_message)
            else:
                message.text=generated_message
                audio(message)
            Stop=False
    else:
            Stop=False
    LedOnOff()
Пример #18
0
    def turn_off(self):
        self.clear()
        lcd.contrast(0)
        backlight.set_all(0, 0, 0)
        lcd.show()
        backlight.show()


#screen = Screen()
#screen.display("hello", "world")
#screen.turn_off()
Пример #19
0
 def draw(image, rgb=(0, 100, 0)):
     backlight.set_all(rgb[0], rgb[1], rgb[2])
     backlight.show()
     lcd.clear()
     for x in range(128):
         for y in range(64):
             pixel = image.getpixel((x, y))
             if pixel > 1:
                 lcd.set_pixel(x, y, 1)
             else:
                 lcd.set_pixel(x, y, 0)
     lcd.show()
Пример #20
0
def horizontalLine(y):
    lcd.clear()
    lcd.show()

    x = 0
    while (x <= 127):
        lcd.set_pixel(x, y, 1)
        x = x + 1

    backlight.set_all(0, 255, 0)
    backlight.show()
    lcd.show()
    return
Пример #21
0
def verticalLine(x):
    lcd.clear()
    lcd.show()

    y = 0
    while (y <= 63):
        lcd.set_pixel(x, y, 1)
        y = y + 1

    backlight.set_all(0, 255, 0)
    backlight.show()
    lcd.show()
    return
def backlightColor():
    choice = input("""
        *** B A C K L I G H T   C O L O U R ***
        Which color do you prefer for the backlight? (enter the number)
            1. red
            2. green
            3. blue
            4. white
            5. Back to MAIN MENU
            > """)
    if (choice == "1"):
        backlight.set_all(255, 0, 0)
        backlight.show()
        menu()
    elif (choice == "2"):
        backlight.set_all(0, 255, 0)
        backlight.show()
        menu()
    elif (choice == "3"):
        backlight.set_all(0, 0, 255)
        backlight.show()
        menu()
    elif (choice == "4"):
        backlight.set_all(255, 255, 255)
        backlight.show()
        menu()
    elif (choice == "5"):
        menu()
    else:
        print("Invalid option.")
        backlightColor()
Пример #23
0
def randomPixels(length):
    lcd.clear()
    lcd.show()
    timestop = time.time() + length
    backlight.set_all(0, 255, 0)
    backlight.show()

    while time.time() <= timestop:
        x = random.randint(1, 127)
        y = random.randint(1, 63)
        lcd.set_pixel(x, y, 1)
        lcd.show()
        time.sleep(0.2)

    return
Пример #24
0
def displayText(text, lcd, x, y):
    lcd.clear()
    backlight.set_all(120, 120, 120)
    backlight.show()
    width, height = lcd.dimensions()
    image = Image.new('P', (width, height))
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype(fonts.AmaticSCBold, 24)
    w, h = font.getsize(text)
    draw.text((x, y), text, 1, font)
    for x1 in range(x, x + w):
        for y1 in range(y, y + h):
            pixel = image.getpixel((x1, y1))
            lcd.set_pixel(x1, y1, pixel)
            lcd.show()
Пример #25
0
def init():
    global paddle1_pos, paddle2_pos, paddle1_vel, paddle2_vel, l_score, r_score
    global score1, score2

    paddle1_pos = [HALF_PAD_WIDTH - 1, HEIGHT // 2]
    paddle2_pos = [WIDTH + 1 - HALF_PAD_WIDTH, HEIGHT // 2]
    l_score = 0
    r_score = 0

    if random.randrange(0, 2) == 0:
        ball_init(True)
    else:
        ball_init(False)

    backlight.set_all(0, 255, 0)
    backlight.show()
Пример #26
0
    def display(self, line1, line2):
        lcd.contrast(40)
        backlight.set_all(self.led_brightness, self.led_brightness,
                          self.led_brightness)
        backlight.show()
        self.draw.text((0, 1), line1, 1, self.font)
        self.draw.text((0, 30), line2, 1, self.fontLine2)
        self.w, self.h = self.font.getsize(self.line1)
        self.x = (self.width - self.w) // 2
        self.y = (self.height - self.h) // 2

        for self.x in range(128):
            for self.y in range(64):
                pixel = self.image.getpixel((self.x, self.y))
                lcd.set_pixel(self.x, self.y, pixel)
        lcd.show()
Пример #27
0
def internet_on():
    while 0 == 0:
        backlight.set_all(
            55, 118, 199
        )  #Backlight colour (I think first is brightness, 0-5, then RGB)
        backlight.show()
        try:
            urllib2.urlopen('http://192.168.1.254', timeout=5)
            xyf = "1"
        except urllib2.URLError as err:
            xyf = "0"
            backlight.set_all(
                41, 89, 152
            )  #Backlight colour (I think first is brightness, 0-5, then RGB)
            backlight.show()
        if xyf == "1":
            break
Пример #28
0
def drawRandomPixels(seconds):
    from random import randint
    from gfxhat import lcd, backlight
    from time import sleep
    from rios0021Library import clearBacklight
    # Clear the lcd
    lcd.clear()
    lcd.show()
    # Clear backlight
    clearBacklight()
    time = 0.0
    # Show a nice blue color
    backlight.set_all(0, 255, 255)
    backlight.show()
    # Loop determined by the number of seconds to draw random pixels every .2 seconds
    while (int(time) != int(seconds)):
        x = randint(0, 127)
        y = randint(0, 63)
        lcd.set_pixel(x, y, 1)
        lcd.show()
        sleep(0.2)
        time += 0.2
    # Show green as signal the pixel drawing has finished
    backlight.set_all(0, 255, 0)
    backlight.show()
    sleep(0.5)
    backlight.set_all(0, 255, 255)
    backlight.show()
    # Clear the lcd and backlight after 4 seconds
    sleep(4)
    lcd.clear()
    lcd.show()
    clearBacklight()
Пример #29
0
def etchSketch(x, y):
    while True:
        key = getchar()
        lcd.set_pixel(x, y, 1)
        lcd.show()
        if key == 's':
            clearScreen(lcd)
            x = 0
            y = 0
        elif key == '\x1b[A':
            y = y - 1
            if y == 0:
                y = 63
            lcd.set_pixel(x, y, 1)
            lcd.show()
        elif key == '\x1b[B':
            y = y + 1
            if y == 63:
                y = 0
            lcd.set_pixel(x, y, 1)
            lcd.show()
        elif key == '\x1b[C':
            x = x + 1
            if x == 127:
                x = 0
            lcd.set_pixel(x, y, 1)
            lcd.show()
        elif key == '\x1b[D':
            x = x - 1
            if x == 0:
                x = 127
            lcd.set_pixel(x, y, 1)
            lcd.show()
        elif key == 'q':
            lcd.clear()
            lcd.show()
            backlight.set_all(0, 0, 0)
            backlight.show()
            exit()
Пример #30
0
    def clear(self):
        self.width, self.height = lcd.dimensions()
        self.image = Image.new('P', (self.width, self.height))
        self.draw = ImageDraw.Draw(self.image)
        self.font = ImageFont.truetype(fonts.FredokaOne, 20)
        self.fontLine2 = ImageFont.truetype(fonts.PressStart2P, 10)
        self.line1 = ""
        self.line2 = ""
        lcd.contrast(40)
        backlight.set_all(self.led_brightness, self.led_brightness,
                          self.led_brightness)
        backlight.show()
        self.draw.text((0, 1), self.line1, 1, self.font)
        self.draw.text((0, 30), self.line2, 1, self.fontLine2)
        self.w, self.h = self.font.getsize(self.line1)
        self.x = (self.width - self.w) // 2
        self.y = (self.height - self.h) // 2

        for self.x in range(128):
            for self.y in range(64):
                pixel = self.image.getpixel((self.x, self.y))
                lcd.set_pixel(self.x, self.y, pixel)
        lcd.show()