Exemplo n.º 1
0
# The number of rows and columns defaults to 4x20, so those
# arguments could be omitted in this case.
lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16)
# 0x27 or 0x3F
button = DigitalInOut(board.D2)
button.direction = Direction.INPUT
button.pull = Pull.UP
button_state = None
last_state = None
value = 0
lcd.print("  CircuitPython        LCD ")
time.sleep(2)
lcd.clear()

lcd.set_cursor_pos(0, 0)
lcd.print("ButtonPresses:")
# Make the cursor visible as a line.
lcd.set_cursor_mode(CursorMode.LINE)
while True:
    if button.value:
            print("not pressed")
    else:
            value = value + 1
        print(value)
        button_state = None
        lcd.set_cursor_pos(1, 0)
        lcd.print(str(value))
        time.sleep(0.2)
# if button is high and last_state = low
    time.sleep(0.01)
Exemplo n.º 2
0
import time
import board
import digitalio
from digitalio import DigitalInOut, Direction, Pull
from lcd.lcd import LCD  # import necessary LCD libraries
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
from lcd.lcd import CursorMode
lcd = LCD(I2CPCF8574Interface(0x3F), num_rows=2,
          num_cols=16)  # sets up LCD screen, 2 x 16

redbutton = digitalio.DigitalInOut(board.D2)  #redbutton on pin D2
redbutton.direction = digitalio.Direction.INPUT  # button is on output
redbutton.pull = digitalio.Pull.UP  #pulling voltage direction

lcd.print("pushes ")  #prints the word pushes on LCD screen
presses = 0  #variable "pushes" equals 0

lcd.set_cursor_mode(
    CursorMode.LINE
)  #moves the cursor down a line on LCD screen for future prints

while True:
    if redbutton.value:  # if the redbutton isn't pressed...
        lcd.set_cursor_pos(1, 4)  #setting cursor position
        lcd.print("PRESSES")
    else:  # when the button is pressed...
        lcd.set_cursor_pos(1, 4)  #setting cursor position
        presses += 1  # add 1 to the presses variable
        lcd.print(presses)  # prints number of presses
        time.sleep
Exemplo n.º 3
0
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
from lcd.lcd import CursorMode

import time
from digitalio import DigitalInOut, Direction, Pull
import board

button = DigitalInOut(board.D2)
button.direction = Direction.INPUT  # sets the button pin for receiving input
button.pull = Pull.UP  # provides power for button

presses = 0  # creates a counter for how many times the button has been pressed

lcd = LCD(I2CPCF8574Interface(0x3F), num_rows=2, num_cols=16)

lcd.set_cursor_mode(CursorMode.LINE)  # Make the cursor visible as a line.

lcd.set_cursor_pos(0, 2)  # Sets position of cursor.
lcd.print("Booting up!")
time.sleep(.5)

while True:
    lcd.set_cursor_pos(0, 0)  # Sets position of cursor.
    lcd.print("Button Presses:")
    if not button.value:
        presses += 1  # shorter way of saying presses = presses + 1
    lcd.set_cursor_pos(1, 0)  # Sets position of cursor.
    lcd.print(str(presses))
    print(button.value)  # tells me if the button is getting pressed
    time.sleep(.01)  # stops it from looping a zillion times a second
Exemplo n.º 4
0
import time
import digitalio
import effects as FX
import presets
import usb_midi
import ui
import midi
import board
from log import log
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
from lcd.lcd import CursorMode

# Setup LCD
lcd = LCD(I2CPCF8574Interface(busio.I2C(scl=board.GP3, sda=board.GP2), 0x27))
lcd.set_cursor_mode(CursorMode.HIDE)

# Setup Custom Chars
lcd.create_char(0, bytearray([0x00, 0x04, 0x08, 0x1F, 0x08, 0x04, 0x00,
                              0x00]))  # Prev
lcd.create_char(1, bytearray([0x00, 0x04, 0x02, 0x1F, 0x02, 0x04, 0x00,
                              0x00]))  # Next
lcd.create_char(2, bytearray([0x00, 0x0E, 0x0A, 0x0E, 0x04, 0x06, 0x06,
                              0x00]))  # Key
log(str("Set Up Custom Characters"))


# Shutdown Function
def shutdown(wait):
    time.sleep(wait)
    lcd.set_backlight(False)