Ejemplo n.º 1
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
Ejemplo n.º 2
0
def off():
    for x in range(6):
        backlight.set_pixel(x, 0, 0, 0)
        touch.set_led(x, 0)
    backlight.show()
    lcd.clear()
    lcd.show()
Ejemplo n.º 3
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()
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
def randomLedColor():
    from gfxhat import backlight
    from random import randint
    for x in range(6):
        backlight.set_pixel(x, randint(0, 255), randint(0, 255),
                            randint(0, 255))
    backlight.show()
Ejemplo n.º 6
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()
Ejemplo n.º 7
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
Ejemplo n.º 8
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()
Ejemplo n.º 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()
Ejemplo n.º 10
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()
Ejemplo n.º 11
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
Ejemplo n.º 12
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()
Ejemplo n.º 13
0
def test_show(sn3218):
    """Test that show calls sn3218.output()."""
    from gfxhat import backlight

    backlight.show()

    sn3218.output.assert_called_with(backlight._buf)
Ejemplo n.º 14
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()
Ejemplo n.º 15
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()
 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()
Ejemplo n.º 17
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()
Ejemplo n.º 18
0
def handler(ch, event):
    if event == 'press':
        led_states[ch] = not led_states[ch]
        touch.set_led(ch, led_states[ch])
        #if led_states[ch]:
        #backlight.set_pixel(ch, 0, 255, 255)
        #else:
        #backlight.set_pixel(ch, 0, 255, 0)
        backlight.show()
Ejemplo n.º 19
0
    def start(self):
        for x in range(6):
            touch.set_led(x, 1)
            time.sleep(0.1)
            touch.set_led(x, 0)

        for x in range(6):
            backlight.set_pixel(x, 255, 79, 193)
        backlight.show()
Ejemplo n.º 20
0
def handler(ch, event):
    if event == "press":
        led_states[ch] = not led_states[ch]
        touch.set_led(ch, led_states[ch])
        if led_states[ch]:
            backlight.set_pixel(ch, 0, 255, 255)
        else:
            backlight.set_pixel(ch, 0, 255, 0)
        backlight.show()
Ejemplo n.º 21
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()
Ejemplo n.º 22
0
 def reboot(self):
     for x in range(6):
         backlight.set_pixel(x, 0, 0, 0)
         touch.set_led(x, 0)
     backlight.show()
     lcd.clear()
     drive = clsDrive.Drive()
     drive.stop()
     lcd.show()
     call("sudo reboot", shell=True)
Ejemplo n.º 23
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")
Ejemplo n.º 24
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()
Ejemplo n.º 25
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()
Ejemplo n.º 26
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()
Ejemplo n.º 27
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
Ejemplo n.º 28
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()
Ejemplo n.º 30
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()