class KeypadDisplay(object):
    def __init__(self,
                 lcd_address,
                 button_pins=[17, 18, 27, 22, 23, 24, 25],
                 led_pins=[16, 20, 21]):
        """Initializes the KeypadDisplay object

        button_pins: A list of 7 GPIO pins used for button inputs, order is A, B, L, U, D, R, C

        pin Usage
        ---|-----------
        17 | Button A
        18 | Button B
        27 | Button Left
        22 | Button Up
        23 | Button Down
        24 | Button right
        25 | Button C

        led_pins: A list of 3 GPIO pins to use for led outputs, order is R, G, B

        pin Usage
        ---|----------
        16 | Red LED
        20 | Yellow LED
        21 | Green LED
        """
        self.button_a = Button(button_pins[0])
        self.button_b = Button(button_pins[1])
        self.button_left = Button(button_pins[2])
        self.button_up = Button(button_pins[3])
        self.button_down = Button(button_pins[4])
        self.button_right = Button(button_pins[5])
        self.button_c = Button(button_pins[6])
        self.led_red = LED(led_pins[0])
        self.led_yellow = LED(led_pins[1])
        self.led_green = LED(led_pins[2])
        self.lcd = LCD(I2CPCF8574Interface(lcd_address),
                       num_rows=4,
                       num_cols=20)

    def set_led(self, value) -> Leds:
        """Sets the LED's according to the passed value"""
        self.led_red.off()
        self.led_yellow.off()
        self.led_green.off()
        if value in [Leds.RED, Leds.ALL]:
            self.led_red.on()
        if value in [Leds.YELLOW, Leds.ALL]:
            self.led_yellow.on()
        if value in [Leds.GREEN, Leds.ALL]:
            self.led_green.on()

    def print(self, message):
        """Clears the LCD and display the message"""
        self.lcd.clear()
        self.lcd.print(message)
Exemplo n.º 2
0
    #Just here becauses it is paired with the RPS printing Below
    if photoPin.value:
        lread = True
    elif fread == lread:
        interrupts += 1
        lread = not lread

#LCD 1 Second Updates

    if now - initial >= 1:
        lcd.clear()
        lcd.set_cursor_pos(0, 0)  #clears and resets LCD

        if (MotorPotOut <= 5000):
            lcd.print(str("Speed: 0"))
        elif (MotorPotOut >= 60000):
            lcd.print("Speed: 100")
        else:
            lcd.print(("Speed: ") + (str(displayMotorPotOut)))

        #RPS Printing
        lcd.set_cursor_pos(1, 0)
        lcd.print(("RPS: ") + str(interrupts))
        interrupts = 0

        #End of the 1 Second Check
        initial = time.monotonic()

    time.sleep(.05)
Exemplo n.º 3
0
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
from digitalio import DigitalInOut, Direction, Pull
from lcd.lcd import CursorMode
import board
# Talk to the LCD at I2C address 0x27.
# 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)
Exemplo n.º 4
0
StateFlipper = False
counterTouched = False

while True:

    # These two if statements make touching the 'switch' wire change the increment from going up to going down and vice versa

    if filippe.value and not StateFlipper:
        state = state * -1
        StateFlipper = True
    if not filippe.value:
        StateFlipper = False

        # These two if statements make touching the 'counter' wire change the lcd screen value, based on if the state is positive or negative

    if button.value and not counterTouched:
        value = value + state
        counterTouched = True
    if not button.value:
        counterTouched = False

        # This block of code prints out the value and the increment on the lcd screen on different lines

    lcd.clear()
    lcd.set_cursor_pos(0, 0)
    lcd.print('Value: ' + str(value))
    lcd.set_cursor_pos(1, 0)
    lcd.print('Change: ' + str(state))
    time.sleep(.05)
Exemplo n.º 5
0
button_a.direction = digitalio.Direction.INPUT
button_a.pull = digitalio.Pull.UP

switch = digitalio.DigitalInOut(board.D8)
switch.direction = digitalio.Direction.INPUT
switch.pull = digitalio.Pull.UP


from lcd.lcd import CursorMode

lcd = LCD(I2CPCF8574Interface(0x27), num_rows=4, num_cols=20)

lcd.clear()

lcd.set_cursor_pos(0,0)
lcd.print("Button presses")

lcd.set_cursor_mode(CursorMode.LINE)
presses = 0
lastbutton = True
while True:
    print(button_a.value)
    time.sleep(.05)
    if not button_a.value and switch.value and lastbutton:
        lcd.set_cursor_pos(1,0)
        presses = presses + 1
        lcd.print(str(presses  ))

        if not button_a.value and not switch.value and lastbutton:
            lcd.set_cursor_pos(1,0)
            presses = presses - 1
Exemplo n.º 6
0
# made a switch
switch = DigitalInOut(board.D6)
switch.direction = digitalio.Direction.INPUT
switch.pull = digitalio.Pull.UP

lcd = LCD(I2CPCF8574Interface(0x27), num_rows=4, num_cols=20)

lcd.clear()

lcd.set_cursor_mode(CursorMode.LINE)

count = 0

buttonValue = True
lcd.set_cursor_pos(0, 0)
lcd.print("buttonValue:")

while True:
    # count up
    if not button.value and switch.value and buttonValue:
        lcd.set_cursor_pos(1,0)
        count = count + 1
        lcd.print(str(count))
        lcd.print("     ")
    # count down 
    if not button.value and not switch.value and buttonValue:
        lcd.set_cursor_pos(1,0)
        count = count - 1
        lcd.print(str(count))
        lcd.print("     ")
    buttonValue = button.value
Exemplo n.º 7
0
# can be 1 or -1
# Add in all of the capacitive touch stuff
touch_pad_green = board.A0  # Will not work for Circuit Playground Express!
touch_pad_yellow = board.A1
touchGreen = touchio.TouchIn(touch_pad_green)
touchYellow = touchio.TouchIn(touch_pad_yellow)

# green will be the counter
# yellow will be the switch

# and the variables for the past values
pastGreen = None
pastYellow = None

lcd.set_cursor_pos(0, 0)
lcd.print("Increment ")

lcd.set_cursor_pos(1, 0)
lcd.print("Value ")

while True:
    if touchYellow.value and not (pastYellow):
        print("Touched Yellow!")
        increment = increment * -1
        lcd.set_cursor_pos(0, 10)
        lcd.print(str(increment) + " ")
        print(increment)

    if touchGreen.value and not (pastGreen):
        print("Touched Green!")
        count = count + increment
Exemplo n.º 8
0
# https://github.com/jkammau97/CircuitPython

import time

import digitalio
import board
photoPin = digitalio.DigitalInOut(board.D5)
photoPin.direction = digitalio.Direction.INPUT
photoPin.pull = digitalio.Pull.UP

from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
lcd = LCD(I2CPCF8574Interface(0x3f), num_rows=2, num_cols=16)

lcd.set_cursor_pos(0, 0)
lcd.print("The number of interrupts is ")

init = time.monotonic()

count = 0
pastInterrupt = False
#returns amount of time elapsed since the program started in SECONDS
while True:
    interrupted = photoPin.value
    now = time.monotonic()
    if interrupted and not (pastInterrupt):
        count = count + 1
        print("interrupt")
    pastInterrupt = interrupted

    if now - init > 4:  # If 4 seconds elapses
Exemplo n.º 9
0
import board
import digitalio
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface

from lcd.lcd import CursorMode

button_a = digitalio.DigitalInOut(board.D3)
button_a.direction = digitalio.Direction.INPUT
button_a.pull = digitalio.Pull.UP

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

lcd.clear()
lcd.set_cursor_pos(0, 0)
lcd.print("Switch State:")

while True:
    if button_a.value:
        lcd.set_cursor_pos(1, 0)
        lcd.print("Presses:")

    else:
        lcd.set_cursor_pos(1, 0)
        lcd.print("Presses:")
        value = value + 1
        lcd.print(str(value))
lcd.set_cursor_mode(CursorMode.LINE)
Exemplo n.º 10
0
switch = DigitalInOut(board.D3)
switch.direction = Direction.INPUT
switch.pull = Pull.UP

button = DigitalInOut(board.D4)
button.direction = Direction.INPUT
button.pull = Pull.UP

pressed = True
lastState = True
count = 0
switched = False
lastswitch = False
dirn = 1

while True:
    lcd.set_cursor_pos(0, 0)
    lcd.print("Counting ",("down","up")[dirn==1])
    pressed = switch.value
    switched = button.value
    if not pressed and lastState:
        count += dirn
    if not switched and lastswtich:
        dirn = -dirn
    lcd.set_cursor_pos(1, 0)
    lcd.print("Presses:        ")
    lcd.set_cursor_pos(1,8)
    lcd.print(str(count))
    lastState = pressed
    lastswitch = switched
Exemplo n.º 11
0
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
lcd = LCD(I2CPCF8574Interface(0x3f), num_rows=2, num_cols=16)
import touchio
import board
import time
import touchio

touch_A0 = touchio.TouchIn(board.A0)  # Which pin the first wire is in
touch_A1 = touchio.TouchIn(board.A1)  # Which pin the second wire is in

x = 0
y = 1

while True:
    if touch_A0.value:
        lcd.clear()
        x = x + 1
        lcd.print(str(x))
        while touch_A0.value:
            print("HelloA0"
                  )  # Prints HelloA0 while the first wire is being touched
    if touch_A1.value:
        lcd.clear()
        x = x - 1
        lcd.print(str(x))
        while touch_A1.value:
            print("HelloA1"
                  )  # Prints HelloA1 while the first wire is being touched
Exemplo n.º 12
0
time.sleep(2)
counter = 0  # counter starts at zero

print("running")
while True:

    if blue.value:  #  blue wire toggles counter direction
        message = "GOING UP  "  #  prints direction
        state = False

    else:
        message = "GOING DOWN "  #  prints direction
        state = True

    lcd.set_cursor_pos(0, 0)  #  first row of lcd screen
    lcd.print(message)  # print direction "up or down"
    if state is True:  # if direction is down
        direction = -1  # subtract 1 from counter
    else:  # if direction is up
        direction = 1  # add 1 to counter

    if yellow.value:
        counter = counter + direction  # controls which way it counts
        lcd.set_cursor_pos(1, 0)  # second line of lcd screen
        message = "PRESS NO. "
        message += str(counter)  # print counter number to lcd
        print(counter)  # prints counter to serial moniter
        lcd.print(message)  # prints press no + counter

    while yellow.value:  # so it doesn't count continuously
        time.sleep(.25)
Exemplo n.º 13
0
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface

from lcd.lcd import CursorMode

# Talk to the LCD at I2C address 0x27.
# The number of rows and columns defaults to 4x20, so those
# arguments could be omitted in this case.
lcd = LCD(I2CPCF8574Interface(0x27), num_rows=4, num_cols=20)

lcd.print("abc ")
lcd.print("This is quite long and will wrap onto the next line automatically.")

lcd.clear()

# Start at the second line, fifth column (numbering from zero).
lcd.set_cursor_pos(1, 4)
lcd.print("Here I am")

# Make the cursor visible as a line.
lcd.set_cursor_mode(CursorMode.LINE)
Exemplo n.º 14
0
lcd = LCD(I2CPCF8574Interface(0x3f), num_rows=2, num_cols=16)

touch_pad1 = board.A0
touch1 = touchio.TouchIn(touch_pad1)

touch_pad2 = board.A1
touch2 = touchio.TouchIn(touch_pad2)

count_direction = "up"
count = 0
needs_refresh = True

while True:
    if needs_refresh:
        lcd.clear()
        lcd.print("Direction: " + count_direction)  # toggles the direction
        lcd.print("   Count: " + str(count))  # counts the numbers
        needs_refresh = False

    if touch1.value:  # if touchpad1 is touched, execute the following code
        needs_refresh = True  # refreshes the lcd
        if count_direction == "up":
            count_direction = "down"
        else:
            count_direction = "up"
        while touch1.value:  #when tachpad1 is being touched, the following code will be executed
            time.sleep(
                0.25)  # wait for .25 seconds from when touchpad1 is touched
            if not touch1.value:  #if touchpad1 is not being touched anymore
                break  # stop
        continue  #if it's still being touched than continue
Exemplo n.º 15
0
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
lcd = LCD(I2CPCF8574Interface(0x3f), num_rows=2, num_cols=16)

interrupter = DigitalInOut(board.D3)
interrupter.direction = Direction.INPUT
interrupter.pull = Pull.UP  #makes the photointerrupter an input

lcd.set_cursor_pos(0, 0)
time.sleep(2)
counter = 0

max = 4  #delay time
start = time.time()
while True:
    lcd.set_cursor_pos(0, 0)
    if interrupter.value:  #if an object passes through, the counter increases by one
        counter += 1
        time.sleep(.20)  # this allows it to count individual passes
    else:
        counter = counter

    remaining = max - time.time()
    if remaining <= 0:
        lcdmessage = "Interruptions: "
        lcdmessage += str(counter)
        lcd.print(lcdmessage)
        print(lcdmessage)

        max = time.time() + 4
        counter = counter
Exemplo n.º 16
0
import board
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
from lcd.lcd import CursorMode
from digitalio import DigitalInOut
import time
# Talk to the LCD at I2C address 0x27 or 0x3F.
lcd = LCD(I2CPCF8574Interface(0x3F), num_rows=2, num_cols=16)
button = DigitalInOut(board.D2)

lcd.print("Ready?")
time.sleep(0.05)
lcd.clear()

# Start at the second line, fifth column (numbering from zero).
lcd.set_cursor_pos(1, 2)
lcd.print("Button Presses :")
lcd.print(0)
while True:

    if button.value:  # button is pushed
    lcd.print(++)
    time.sleep(0.05)
# Make the cursor visible as a line.
lcd.set_cursor_mode(CursorMode.LINE)
Exemplo n.º 17
0
switch = DigitalInOut(board.D13)  #setting the pin for switch
switch.direction = Direction.INPUT
switch.pull = Pull.UP

counter = 0  #counter starts at zero

now = True
later = True
switchValue = True

while True:
    now = button.value
    switchValue = switch.value
    print(str(switchValue))  #print if the switch is up or down
    if now == False and later == True:
        if switchValue:  #if switch is up count up
            counter += 1  #go up by 1
        if not switchValue:  #if switch is down count down
            counter -= 1  #go down by one
        lcd.set_cursor_pos(0, 0)  #where the lcd is printing
        lcd.print("button presses: ")
        lcd.set_cursor_pos(1, 0)
        lcd.print(str(
            counter))  #print the number of times the button has been pressed
        lcd.print("  ")  #to clear the previous number
        time.sleep(0.05)
        now = True
        later = button.value
    time.sleep(.05)
Exemplo n.º 18
0
from lcd.lcd import CursorMode
switch = DigitalInOut(board.D2)
switch.direction = Direction.INPUT
switch.pull = Pull.UP
switch2 = DigitalInOut(board.D7)
switch2.direction = Direction.INPUT
switch2.pull = Pull.UP
# Talk to the LCD at I2C address 0x27.
# 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)
presses = 0
fread = True
while True:
    lcd.set_cursor_pos(0, 0)
    lcd.print("SwitchState:")
    if switch.value:
        fread = True
    else:
        if fread == True:
            if switch2.value:
                lcd.print("Up")
                lcd.print("    ")
                presses += 1
                fread = not fread
            else:
                lcd.print("Down")
                lcd.print("    ")
                presses -= 1
                fread = not fread
    lcd.set_cursor_pos(1, 0)
Exemplo n.º 19
0
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
import digitalio
import board
import time
from lcd.lcd import CursorMode

# Talk to the LCD at I2C address 0x27.
# The number of rows and columns defaults to 2x16, so those
# arguments could be omitted in this case.
lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16)

lcd.clear()

lcd.print("Switch State:")
lcd.set_cursor_pos(0, 0)


button_a = digitalio.DigitalInOut(board.D2)
button_a.direction = digitalio.Direction.INPUT
button_a.pull = digitalio.Pull.DOWN

counter = 0
while True:
    if button_a.value:
        counter += 1
        lcd.set_cursor_pos(1, 4)
        lcd.print(str(counter))
        time.sleep(0.1)
    else:
        counter = counter
Exemplo n.º 20
0
lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16)

button_a = digitalio.DigitalInOut(board.D7)
button_a.direction = digitalio.Direction.INPUT
button_a.pull = digitalio.Pull.UP

button_b = digitalio.DigitalInOut(board.D2)
button_b.direction = digitalio.Direction.INPUT
button_b.pull = digitalio.Pull.UP

count = 0

while True:
    if not button_a.value:
        if button_b.value:
            count += 1
            lcd.clear()
            lcd.set_cursor_pos(0, 0)
            lcd.print("ButtonState:UP")
        else:
            count -= 1
            lcd.clear()
            lcd.set_cursor_pos(0, 0)
            lcd.print("ButtonState:DOWN")
        lcd.set_cursor_pos(1, 0)
        lcd.print("Presses:")
        lcd.set_cursor_pos(1, 8)
        lcd.print(str(count))
        time.sleep(0.0)
Exemplo n.º 21
0
# Bob Kammauff
# circuitPythonLCD
# https://github.com/jkammau97/CircuitPython
# code from https://cvilleschools.instructure.com/courses/31071/assignments/303469
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
# some LCDs are 0x3f... some are 0x27.
lcd = LCD(I2CPCF8574Interface(0x3f), num_rows=2, num_cols=16)

lcd.print("Hello, Engineer!")
Exemplo n.º 22
0
import time
import board
from digitalio import DigitalInOut, Direction, Pull
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
from lcd.lcd import CursorMode
led = DigitalInOut(board.D13)
lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16)
switch = DigitalInOut(board.D2)
switch.direction = Direction.INPUT
switch.pull = Pull.UP
value = 0
lcd.set_cursor_pos(0, 1)
lcd.print("ButtonPress:")
while True:
    if switch.value:
        lcd.set_cursor_pos(0, 14)
    else:
        lcd.set_cursor_pos(0, 14)
        value = value + 1
        lcd.print(str(value))
        time.sleep(0.3)
Exemplo n.º 23
0
import board
from digitalio import DigitalInOut, Direction, Pull


button = DigitalInOut(board.D8)
button.direction = Direction.INPUT
button.pull = Pull.UP

# Talk to the LCD at I2C address 0x27.
# The number of rows and columns defaults to 4x20, so those
# arguments could be omitted in this case.S
lcd = LCD(I2CPCF8574Interface(0x3f), num_rows=2, num_cols=16)


lcd.set_cursor_pos(1,4)
lcd.print("button presses")
lcd.clear()

counter = 0

now = True
later = True
while True:
    now = button.value
    if  now == False and later == True:
            lcd.set_cursor_pos(0,0)
            lcd.print("pushed")
            lcd.sec_cursor_pos (1,1)
            lcd.print(str(counter))
            time.sleep(0.05)
            counter += 1
Exemplo n.º 24
0
from lcd.lcd import CursorMode

switch = DigitalInOut(board.D7)
button = DigitalInOut(board.D2)
switch.direction = Direction.INPUT
button.direction = Direction.INPUT
switch.pull = Pull.DOWN
button.pull = Pull.DOWN
presses = 0
direction = 1
lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16)
toggle1 = 0

while True:
    lcd.set_cursor_pos(0, 0)
    lcd.print("Switch: ")
    lcd.set_cursor_pos(1, 0)
    lcd.print("Presses:")
    if switch.value and not button.value:
        direction = 1
        lcd.clear()
        lcd.set_cursor_pos(0, 8)
        lcd.print("UP")
        print("UP")
    if button.value and toggle1 == 0 and not switch.value:
        toggle1 = 1
        presses += direction
        lcd.set_cursor_pos(1, 9)
        lcd.print(str(presses))
        lcd.print("       ")
        print(str(presses))
Exemplo n.º 25
0
switch.pull = Pull.UP
lcd.set_cursor_mode(CursorMode.LINE)

press = False
x = 0

while True:
    print(button.value)
    lcd.backlight = True
    if not button.value:
        if (press == False):
            press = True
            if not switch.value:
                x = x - 1
            if switch.value:
                x = x + 1
        print((0, ))
    if button.value:
        press = False
    lcd.set_cursor_pos(0, 0)
    lcd.print("Presses: ")
    lcd.set_cursor_pos(0, 10)
    lcd.print(str(x))
    lcd.print("    ")
    lcd.set_cursor_pos(1, 0)
    lcd.print("Switch:  ")
    if not switch.value:
        lcd.print("DOWN")
    if switch.value:
        lcd.print("UP  ")
    time.sleep(0.05)
Exemplo n.º 26
0
    # so that this if statement will only run once per interrupt
    if pi.value and toggle:
        interrupts += 1
        g = 255
        r = 0
        toggle = False

    # changing neopixel color and setting toggle to True so that the if statement ^^^
    # can run again
    if not pi.value:
        r = 255
        g = 0
        toggle = True

    # FUN TIME TIME

    # if the time_toggle variable is True, run this statement
    if time_toggle:
        current_time = time.time(
        )  # setting current_time variable as time.time(), a variable that returns the seconds since some event
        # important part - the variable increases by one every second
        time_toggle = False  # so that this statement only runs once per every four seconds
        lcd.print("Number of")
        lcd.set_cursor_pos(1, 0)
        lcd.print("Interrupts: " + str(interrupts))

    # will run if the current time is four less than the current time
    if current_time == time.time() - 4:
        time_toggle = True  # so that the if statement ^^^ can run again
        lcd.clear()
Exemplo n.º 27
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
analog_out = AnalogOut(board.A0)

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

button_a = digitalio.DigitalInOut(board.D1)
button_a.direction = digitalio.Direction.INPUT
button_a.pull = digitalio.Pull.DOWN

button_b = digitalio.DigitalInOut(board.D2)
button_b.direction = digitalio.Direction.INPUT
button_b.pull = digitalio.Pull.DOWN

up = 1
number = 0

while True:

    lcd.set_cursor_pos(0, 0)
    lcd.print("Switch State: ")  #prints out "switch state on lcd screen
    lcd.print(
        str(up))  #prints out the number that corresponds to the variable "up"
    lcd.set_cursor_pos(1, 0)
    lcd.print("presses:")  #prints out "presses:" below "switch state"

    if button_a.value:
        number += up  #if button a is pressed then it adds 1 to "up"

    if button_b.value:
        up *= -1  #if button a is pressed then it changes what is next to switchstate, either 1 or -1
    lcd.print(str(number))
    lcd.print("     ")
Exemplo n.º 29
0
button.direction = digitalio.Direction.INPUT  #setup button
button.pull = digitalio.Pull.DOWN

switch = digitalio.DigitalInOut(board.D5)
switch.direction = digitalio.Direction.INPUT  #setup switch
switch.pull = digitalio.Pull.DOWN

upDown = 1
buttonState = 0  #create variables
number = 0

while True:  #loop

    if not buttonState and button.value:
        number += upDown  #count when button is pressed
    buttonState = button.value

    if switch.value:
        upDown = 1  #should the number go up or down?
    else:
        upDown = -1

    lcd.set_cursor_pos(0, 0)
    lcd.print("up or down: ")
    if upDown == 1:
        lcd.print("up  ")  #print things to LCD
    else:
        lcd.print("down")
    lcd.print("number is: ")
    lcd.print(str(number))
    lcd.print("    ")
Exemplo n.º 30
0
import time
# import math
import board
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
from digitalio import DigitalInOut, Direction, Pull
from lcd.lcd import CursorMode
photo = DigitalInOut(board.D8)

photo.direction = Direction.INPUT
photo.pull = Pull.UP
lcd = LCD(I2CPCF8574Interface(0x3f), num_rows=2, num_cols=16)
photoState = True
oldPhoto = True
value = 0

while True:
    photoState = photo.value

    if photoState and not oldPhoto:
        value = value + 1
        lcd.set_cursor_pos(1, 0)
        lcd.print(str(value))

    else:
        lcd.set_cursor_pos(1, 0)
        lcd.print(str(value))

    oldPhoto = photoState