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 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()
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()
Exemple #4
0
def etchSketch():
    import click
    from gfxhat import lcd, backlight
    from random import randint
    import os
    print("Etch a Sketch running, use arrow keys to draw, 's' to restart or 'q' to exit...")
    exit = False
    x = 64
    y = 32
    clearScreen()
    displayText("Etch a Sketch", 40, 54)
    while(exit != True):
        keyPressed = click.getchar()
        if(keyPressed == '\x1b[A'):
            y = drawPixelUp(x,y)
            randomLedColor()
        elif(keyPressed == '\x1b[B'):
            y = drawPixelDown(x,y)
            randomLedColor()
        elif(keyPressed == '\x1b[C'):
            x = drawPixelRight(x,y)
            randomLedColor()
        elif(keyPressed == '\x1b[D'):
            x = drawPixelLeft(x,y)
            randomLedColor()
        elif(keyPressed == 'q' or keyPressed == 'Q'):
            exit = True
            clearScreen()
            clearBacklight()
        elif(keyPressed == 's' or keyPressed == 'S'):
            clearScreen()
            displayText("Etch a Sketch", 40, 54)
        os.system("cls||clear")
        print("Etch a Sketch running, use arrow keys to draw, 's' to restart or 'q' to exit...")
def colorRainbow(numberOfLoops):
    from gfxhat import lcd, backlight
    from time import sleep
    from rios0021Library import clearBacklight
    aux = 0
    r = 255
    g = 0
    b = 0
    lcd.clear()
    lcd.show()
    backlight.set_all(r, g, b)
    backlight.show()
    while (aux < numberOfLoops):
        if (r == 255 and g < 255 and b == 0):
            g += 1
            backlight.set_all(r, g, b)
            backlight.show()
        elif (r != 0 and g == 255):
            r -= 1
            backlight.set_all(r, g, b)
            backlight.show()
        elif (r == 0 and b < 255 and g == 255):
            b += 1
            backlight.set_all(r, g, b)
            backlight.show()
        elif (g != 0 and b == 255):
            g -= 1
            backlight.set_all(r, g, b)
            backlight.show()
        elif (g == 0 and r < 255 and b == 255):
            r += 1
            backlight.set_all(r, g, b)
            backlight.show()
        else:
            b -= 1
            backlight.set_all(r, g, b)
            backlight.show()
            if (b == 0):
                aux += 1
    # Turn off backlight after 2 seconds
    sleep(2)
    clearBacklight()
Exemple #6
0
        # Loop through each line in the file
        for line in opFile:
            binList = []
            # Separate values from each line with the comma
            auxList = line.split(',')
            # Assign values to descriptive variables
            baseNo = auxList[0][2:]
            keyChar = auxList[1].rstrip()
            # Transform hex to bin and fill the zeroes at the start if removed
            binNumber = bin(int(baseNo, 16))[2:].zfill(64)
            # Loop 8 times to split the bin number and create the list of lists
            for i in range(1, 9):
                aux = (i * 8)
                binList.append(list(binNumber[aux - 8:aux]))
            # Assign the key and list of lists to the dictionary
            valuesDictionary[keyChar] = binList
        opFile.close()
        return valuesDictionary
    except:
        print('Function generateDictionary failed')


newDictionary = generateDictionary()
askChar = input('Please enter a character to display in the gfxhat: ')
try:
    rios0021Library.clearScreen()
    rios0021Library.clearBacklight()
    rios0021Library.randomLedColor()
    rios0021Library.displayObject(newDictionary[askChar], 60, 30)
except:
    print('Something went wrong with displayObject')