Beispiel #1
0
def handler(channel, event):
    global y, x
    print("Got {} on channel {}".format(event, channel))
    if (channel == 2 and event == 'press'):  #  QUIT
        print("QUIT")
        lcd.clear()
        lcd.show()
        os._exit(1)
    elif (channel == 4 and event == 'press'):  # RESET
        x = 60
        y = 30
        lcd.clear()
        lcd.set_pixel(x, y, 1)
        displayText('Etch a Sketch', lcd, 20, 10)
    elif (channel == 1 and event == 'press'):  # DOWN
        y = y + 1
        if y > 63:
            y = 0
        lcd.set_pixel(x, y, 1)
    elif (channel == 0 and event == 'press'):  # UP
        y = y - 1
        if y < 0:
            y = 63
        lcd.set_pixel(x, y, 1)
    elif (channel == 3 and event == 'press'):  # LEFT
        x = x - 1
        if x < 0:
            x = 127
        lcd.set_pixel(x, y, 1)
    elif (channel == 5 and event == 'press'):  # RIGHT
        x = x + 1
        if x > 127:
            x = 0
        lcd.set_pixel(x, y, 1)
    lcd.show()
Beispiel #2
0
def displayObject(obj, x, y):
    from gfxhat import lcd
    # While loop to translate any entered number into a existing space in the gfxhat display
    while (x < 0 or y < 0 or x > 127 or y > 63):
        if (x < 0):
            x = 128 + x
        if (y < 0):
            y = 64 + y
        if (x > 127):
            x = x - 128
        if (y > 63):
            y = y - 63
    navX = x
    navY = y
    for aux in obj:
        for aux2 in aux:
            if (aux2 == 1):
                lcd.set_pixel(navX, navY, 1)
                lcd.show()
            navX += 1
            if (navX > 127):
                navX = 0
        navY += 1
        if (navY > 63):
            navY = 0
        navX = x
Beispiel #3
0
def gfxDisplay(image):
    image = mdlPil.rotateImage(image, 180)
    for x in range(128):
        for y in range(64):
            pixel = image.getpixel((x, y))
            lcd.set_pixel(x, y, pixel)
    lcd.show()
Beispiel #4
0
def downArrowPressed(down, xDown=x2, yDown=y2):
    print(down)
    print(xDown)
    print('first down arrow', yDown)
    while down == '\x1b[B':
        down = getchar()
        print('second down arrow', yDown)
        if yDown == 63:
            print('third down arrow', yDown)
            yDown = 0
            yDown += 1
            print('fourth down arrow', yDown)
            lcd.set_pixel(xDown, yDown, 1)
            lcd.show()

        if yDown >= 0:
            yDown += 1
            lcd.set_pixel(xDown, yDown, 1)

            print('fifth down arrow', yDown)
            lcd.show()
        if down == '\x1b[C':
            rightArrowPressed(down, xDown, yDown)
        if down == '\x1b[A':
            upArrowPressed(down, xDown, yDown)
        if down == '\x1b[D':
            leftArrowPressed(down, xDown, yDown)
        else:
            pass
Beispiel #5
0
def leftArrowPressed(left, xLeft=x2, yLeft=y2):
    print(left)
    print(yLeft)
    print('first left arrow', xLeft)
    while left == '\x1b[D':
        left = getchar()
        print('second left arrow', xLeft)
        if xLeft == 0:
            print('fourth right arrow', xLeft)
            xLeft = 127
            xLeft -= 1
            print('fifth right arrow', xLeft)
            lcd.set_pixel(xLeft, yLeft, 1)
            lcd.show()

        if xLeft >= 1:
            xLeft -= 1
            lcd.set_pixel(xLeft, yLeft, 1)

            print('third right arrow', xLeft)
            lcd.show()
        if left == '\x1b[A':
            upArrowPressed(left, xLeft, yLeft)
        if left == '\x1b[B':
            downArrowPressed(left, xLeft, yLeft)
        if left == '\x1b[C':
            rightArrowPressed(left, xLeft, yLeft)
        else:
            pass
Beispiel #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()
Beispiel #7
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()
Beispiel #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()
Beispiel #9
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()
Beispiel #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()
Beispiel #11
0
    def paint_screen(self):
        try:
            self.__image.paste(0, (0, 0, self.__lcdWidth, self.__lcdHeight))

            if self.__trigger_action:
                self.__menu_options[self.__current_menu_option].trigger()
                self.__trigger_action = False

            if(len(self.__menu_options) > 0):
                self.paint_menu_buffered()
            else:
                self.paint_settings_screen()

            if(self.__timer.is_running == False):
                if(self.__debug):
                    print("Timer is not running")
                self.__timer.start()
                if(self.__debug):
                    print("Timer started")

            lcd.show()

        except KeyboardInterrupt:
            self.__looper = False
            self.cleanup()
Beispiel #12
0
def horizontalline(y):
    from gfxhat import lcd
    lcd.clear()

    for i in range(128):
        lcd.set_pixel(i, y, 1)
        lcd.show()
Beispiel #13
0
def verticalline(x):
    from gfxhat import lcd
    lcd.clear()

    for i in range(64):
        lcd.set_pixel(x, i, 1)
        lcd.show()
def displayObject(obj, x, y):
    lcd.clear()
    xp = x

    # looping over y coordinate
    for y1 in obj:

        # looping over x coordinate
        for x2 in y1:
            lenY = len(obj)
            lenX = len(y1)

            if x2 == 1:
                pixel = 1
            else:
                pixel = 0

            lcd.set_pixel(xp, y, pixel)
            xp = xp + 1

        y = y + 1
        lcd.set_pixel(xp, y, pixel)
        xp = x

    lcd.show()
Beispiel #15
0
def horizontalLine(y):
    x = 0
    while (x < 128):
        lcd.set_pixel(x, y, 1)
        x += 1

    lcd.show()
Beispiel #16
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)
Beispiel #17
0
def displayObject(obj, x, y):
    from gfxhat import lcd, fonts
    from PIL import Image, ImageFont, ImageDraw
    row = []
    initialX = x
    # Clearing Screen
    lcd.clear()
    lcd.show()

    # Resetting y and/or x to 0 if the initial value is too high
    if y > 63:
        y = 0
    if initialX > 127:
        initialX = 0

# Starting for loops to draw object
    for i in range(len(obj)):
        row = obj[i]
        y = y + 1
        x = initialX
        # Resetting y if the value gets too high
        if y > 63:
            y = 0
        for i in range(len(row)):
            if row[i] == 1:
                lcd.set_pixel(x, y, 1)
                lcd.show()
            x = x + 1
            # Resetting x if the value gets too high
            if x > 127:
                x = 0 + i
Beispiel #18
0
def sketch(x, y):

    while True:
        inp = getchar()

        if inp == '\x1b[A':  # up
            y -= 1
            if y == 0:
                y = 63
        if inp == '\x1b[B':  # down
            y += 1
            if y == 63:
                y = 0
        if inp == '\x1b[C':  # right
            x += 1
            if x == 127:
                x = 0
        if inp == '\x1b[D':  # left
            x -= 1
            if x == 0:
                x = 127
        if inp == "s":
            clearScreen(lcd)
        elif inp == "q":
            break
        else:
            lcd.set_pixel(x, y, 1)
            lcd.show()
Beispiel #19
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()
Beispiel #20
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()
Beispiel #21
0
def etchSketch(x=1, y=1, pixel=1):
    while True:
        inp = getchar()
        lcd.set_pixel(x, y, 1)
        lcd.show()
        if inp == 's':
            clearScreen(lcd)
        if inp == '\x1b[A':
            print("up key")
            y = y - 1
            if y == 0:
                y = 63
            lcd.set_pixel(x, y, 1)
            lcd.show()
        elif inp == '\x1b[B':
            print("down key")
            y = y + 1
            if y == 63:
                y = 0
            lcd.set_pixel(x, y, 1)
            lcd.show()
        elif inp == '\x1b[C':
            print("right key")
            x = x + 1
            if x == 127:
                x = 0
            lcd.set_pixel(x, y, 1)
            lcd.show()
        elif inp == '\x1b[D':
            print("left key")
            x = x - 1
            if x == 0:
                x = 127
            lcd.set_pixel(x, y, 1)
            lcd.show()
Beispiel #22
0
def staircase(x, y, w, h):
    # x = 30
    # y = 63

    setRedBG()
    while x < 127 and y >= 0:

        for i in range(0, w):
            x = x + 1
            if (x > 127):
                break

            lcd.set_pixel(x, y, 1)
            lcd.show()

        for i in range(0, h):
            y = y - 1
            if (y < 0):
                break
            lcd.set_pixel(x, y, 1)
            lcd.show()

    # lcd.show()

    setGreenBG()
Beispiel #23
0
def rightArrowPressed(right, xRight=x2, yRight=y2):
    print(right)
    print(yRight)
    print('first right arrow', xRight)
    while right == '\x1b[C':
        right = getchar()
        print('second right arrow', xRight)
        if xRight >= 0:
            xRight += 1
            lcd.set_pixel(xRight, yRight, 1)

            print('third right arrow', xRight)
            lcd.show()
        if xRight == 127:
            print('fourth right arrow', xRight)
            xRight = 0
            xRight += 1
            print('fifth right arrow', xRight)
            lcd.set_pixel(xRight, yRight, 1)

            lcd.show()
        if right == '\x1b[A':
            upArrowPressed(right, xRight, yRight)
        if right == '\x1b[B':
            downArrowPressed(right, xRight, yRight)
        if right == '\x1b[D':
            leftArrowPressed(right, xRight, yRight)
        else:
            pass
Beispiel #24
0
def displayObjectNoAnimation(obj, coorX, coorY, off=False):

    x = coorX  # -1
    y = coorY  # -1

    # Validations
    if ((coorX + len(obj[0])) > 127):
        # coorX = -1
        coorX = 127 - len(obj[0])

    if (coorY + len(obj) > 62):
        y = 63 - len(obj)

    for line in obj:
        y = y + 1
        x = coorX

        for val in line:
            x = x + 1
            if (off):
                val = 0

            lcd.set_pixel(x, y, val)

    lcd.show()
Beispiel #25
0
def upArrowPressed(up, xup=x2, yup=y2):
    print(up)
    print(xup)
    print('first up arrow', yup)
    while up == '\x1b[A':
        up = getchar()
        print('second up arrow', yup)
        if yup <= 63:
            yup -= 1
            lcd.set_pixel(xup, yup, 1)
            print('third up arrow', yup)
            lcd.show()
        if yup == 0:
            print('fourth up arrow', yup)
            yup = 63
            # yup -= 1
            print('fifth up arrow', yup)
            lcd.set_pixel(xup, yup, 1)
            lcd.show()

        if up == '\x1b[C':
            rightArrowPressed(up, xup, yup)
        if up == '\x1b[B':
            downArrowPressed(up, xup, yup)
        if up == '\x1b[D':
            leftArrowPressed(up, xup, yup)
        else:
            pass
Beispiel #26
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
Beispiel #27
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()
Beispiel #28
0
def verticleLine(x):
    y = 0
    while (y < 64):
        lcd.set_pixel(x, y, 1)
        x += 1

    lcd.show()
def drawSquare(xSquare, ySquare, side):
    a = xSquare
    b = ySquare
    z = xSquare + side
    zz = ySquare + side
    for i in range(0, side):
        xSquare += 1
        print(xSquare, 'first')
        if xSquare > z:
            break
        lcd.set_pixel(xSquare, ySquare, 1)
    for j in range(0, side):
        ySquare += 1
        if ySquare > zz:
            break
        lcd.set_pixel(xSquare, ySquare, 1)
        print(xSquare, ySquare, 'display')
    for k in range(0, side):
        xSquare -= 1
        if xSquare < a:
            break
        lcd.set_pixel(xSquare, ySquare, 1)

    for l in range(0, side):
        ySquare -= 1
        if ySquare < b:
            break
        lcd.set_pixel(xSquare, ySquare, 1)
    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()