Пример #1
0
import time
import board
import touchio
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)

touch_pad1 = board.A0
switch = touchio.TouchIn(touch_pad1)
touch_pad2 = board.A1
button = touchio.TouchIn(touch_pad2)

change = 1
value = 0
switchFlipped = False
buttonPressed = False

lcd.print("Hello, Engineer!")
while True:

    # Adjusts increment and value based on if the wires are touched
    if switch.value and not switchFlipped:
        change = change * -1
        switchFlipped = True
    if not switch.value:
        switchFlipped = False
    if button.value and not buttonPressed:
        value = value + change
        buttonPressed = True
    if not button.value:
import board
import time
import digitalio
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
from lcd.lcd import CursorMode
from analogio import AnalogOut

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"
Пример #3
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)
Пример #4
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)
Пример #5
0
#Assignment 3 Lcd and buttons

from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
import board
from lcd.lcd import CursorMode
import digitalio

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

button = digitalio.DigitalInOut(board.D2)
button.direction = digitalio.Direction.INPUT  #Defines Button
button.pull = digitalio.Pull.DOWN

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

buttonState = 0
switchState = 1
number = 0

while True:

    if not buttonState and button.value:
        number += switchState
    buttonState = button.value
Пример #6
0
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
from lcd.lcd import CursorMode
import time
import board
from digitalio import DigitalInOut, Direction, Pull

# Talk to the LCD at I2C address 0x27 or 0x3F
lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16)

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:
Пример #7
0
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
from digitalio import DigitalInOut, Direction, Pull
import board
import time
import digitalio
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:
Пример #8
0
# Bob Kammauff
# circuitPythonLCD
# https://github.com/jkammau97/CircuitPython
# code from https://cvilleschools.instructure.com/courses/31071/assignments/303469
import time
# for time
import board
# for pin references
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!")
time.sleep(1)
lcd.clear()

while True:
    lcd.set_cursor_pos(0,0)
    lcd.print("Hi")
    time.sleep(1)
    lcd.clear()
    lcd.set_cursor_pos(1,0)
    lcd.print("Bob")
    time.sleep(1)
    lcd.clear()
Пример #9
0
import busio
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)
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
button = DigitalInOut(board.D8)

button.direction = Direction.INPUT
button.pull = Pull.UP
lcd = LCD(I2CPCF8574Interface(0x3f), num_rows=2, num_cols=16)
buttonState = True
oldButton = True
value = 0

while True:
    buttonState = button.value
    print(oldButton, buttonState)

    if not button.value and oldButton:
        value = value + 1
        lcd.set_cursor_pos(0, 0)
        lcd.print("Now Pressed")
        lcd.set_cursor_pos(1, 0)
        lcd.print(str(value))

    else:
        lcd.set_cursor_pos(0, 0)
        print(value)
        lcd.print("Not Pressed   ")
Пример #11
0
import time
from lcd.lcd import LCD
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(0x3F), 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)
Пример #12
0
import time
import board
import digitalio
from lcd.lcd import LCD #importing the required libraries
from lcd.lcd import CursorMode
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface

lcd = LCD(I2CPCF8574Interface(0x3f), num_rows=2, num_cols=16) #setup LCD

PI = digitalio.DigitalInOut(board.D8)
PI.direction = digitalio.Direction.INPUT #setup photointerrupter
PI.pull = digitalio.Pull.UP

number = 0
time2 = 0 # variables
now = 0
PIstate = 0

while True:
    now = time.monotonic()
    if now - time2 > 3.999: # do every 4 seconds

        lcd.clear()
        lcd.print("there have been ")
        lcd.print(str(number)) # print # of interruptions
        lcd.print(" interruptions")
        time2 = now

    if PIstate and not PI.value:
        number += 1 # count interruptions
    PIstate = PI.value
Пример #13
0
import time
import board  #these libraries are needed
from digitalio import DigitalInOut, Direction, Pull
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface

lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16)
PI = DigitalInOut(board.D5)
PI.direction = Direction.INPUT  #making photointerrupter pin and declaring as DigitalInOut object
PI.pull = Pull.UP

x = 0  #Set at zero until proven otherwise

interrupt = False
while True:
    #print(PI.value)
    lcd.backlight = True
    if PI.value:
        if interrupt == False:
            interrupt = True  #if interrupt isn't false then it is true
            x = x + 1  #count up by one if PI value
    if not PI.value:
        interrupt = False  #if not PI value then it is back to starting x=0
        x = x

    #print(("Interrupted"))
    if time.monotonic() % 4 == 0:  #print value every 4 times PI is interrupted
        lcd.set_cursor_pos(0, 0)  #cursor at start of first row
        lcd.print("Interrupted: ")
        lcd.set_cursor_pos(0, 12)  #cursor at end of first row
        lcd.print(str(x))
#import touchio
from lcd.lcd import LCD

from lcd.i2c_pcf8574_interface import I2CPCF8574Interface

from lcd.lcd import CursorMode

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

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

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

counter = 0
oldSwitchState = 0
newSwitchState = 1
adder = 1

while True:

    lcd.clear()
    lcd.set_cursor_pos(1, 0)
    lcd.print("pressed:")

    lcd.set_cursor_pos(1, 9)
    lcd.print(str(counter))
Пример #15
0
import board
import touchio
import time
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface

# some LCDs are 0x3f... some are 0x27, import all libraries for lcd
lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16)
state = True
yellow = touchio.TouchIn(board.A3)  # establishes yellow wire at A3
blue = touchio.TouchIn(board.A4)  # establishes blue wire at A4
lcd.set_cursor_pos(0, 0)  # starting position is first row of lcd
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
Пример #16
0
import time
import board
import busio
from digitalio import DigitalInOut, Direction, Pull
from lcd.lcd import LCD
from lcd.lcd import CursorMode
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16)

counter = 0


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

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


lcd.backlight = True


while True:
    if button.value:
        lcd.set_cursor_pos(0,0)
        lcd.print("Presses:  ")
        lcd.print(str(counter))
        time.sleep(.05)
    elif switch.value:
Пример #17
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
Пример #18
0
# int encoderBump;
pidToggle = false
saved = false
lastRPM = 0.0
# long now;
msDelay = 250
float RPM;
slots = 5
# volatile int count = 0;
multiplier = 60*(1000/msDelay)/slots
# float error, lastError;
# float P, I, D, drive;

i2c = board.I2C()
# some LCDs are 0x3f... some are 0x27.
lcd = LCD(I2CPCF8574Interface(i2c, 0x3f), num_rows=2, num_cols=16)

encoder = rotaryio.IncrementalEncoder(board.D10, board.D9)
button = digitalio.DigitalInOut(RotaryButton)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP

''' Some Timer1 stuff that may be related to pwm or rotary encoder
	Timer1.initialize(1000);
  	Timer1.attachInterrupt(timerIsr); 
  	last = -1;
'''

'''LCD is already setup, no init needed
	lcd.begin();
	lcd.backlight();
Пример #19
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)
Пример #20
0
# LCD button presses
# Lily Wielar
# counts how many times a button was pressed and displays this number on an LCD screen

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
Пример #21
0
import time
import board
import digitalio

from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface

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")
Пример #22
0
motorPot = AnalogIn(board.A5)

#PhotoInteruppter SetUp
photoPin = digitalio.DigitalInOut(board.D8)
photoPin.direction = digitalio.Direction.INPUT
photoPin.pull = digitalio.Pull.UP
interrupts = -1
lread = True
fread = True

#LCD Set Up
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
from lcd.lcd import CursorMode
lcd = LCD(I2CPCF8574Interface(0x3F), num_rows=2, num_cols=16)

initial = time.monotonic()

while True:

    now = time.monotonic()

    mappedShaftPot = int(shaftPot.value / 2**16 * 180)
    shaftServo.angle = int(mappedShaftPot)
    #print(str("Shaft Servo: ") + (str(shaftServo.angle)))

    mappedPitchPot = int(pitchServoPot.value / 2**16 * 180)
    pitchServo.angle = int(mappedPitchPot)
    #print(str("Pitch Servo: ") + (str(pitchServo.angle)))
Пример #23
0
import board
import time
from digitalio import DigitalInOut, Direction, Pull
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
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
Пример #24
0
from digitalio import DigitalInOut, Direction, Pull
import time
import board

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)
Пример #25
0
import neopixel
import time
from digitalio import DigitalInOut, Direction, Pull
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface

from lcd.lcd import CursorMode

# declaring photointerrupter as a DigitalInOut object
pi = DigitalInOut(board.D6)
pi.direction = Direction.INPUT
pi.pull = Pull.UP

# declaring the dot as the neopixel on the board and lcd as LCD object
dot = neopixel.NeoPixel(board.NEOPIXEL, 1)
lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16)

# semi-useless variables for r, g, b values for neopixel
r = 255
g = 0
b = 0

# happy and fun toggles for photointerrupter and time (elaborated on more)
toggle = True
time_toggle = True

# declaring current_time as a variable and declaring interrupts (variable being displayed
# on the lcd
current_time = 0

interrupts = 0
Пример #26
0
import touchio
import analogio
import digitalio
import board
import time

from lcd.lcd import LCD
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)

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
Пример #27
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
Пример #28
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)
Пример #29
0
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
from lcd.lcd import CursorMode
import time
import board
from digitalio import DigitalInOut, Direction, Pull

lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2,
          num_cols=16)  #setting up the lcd
lcd.set_cursor_pos(0, 0)  #where the lcd will start printing

button = DigitalInOut(board.D2)  #setting the pin for button
button.direction = Direction.INPUT
button.pull = Pull.UP  #

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
Пример #30
0
# defining variables for the r, g, b values for the built-in led
# on the board

button_alt = DigitalInOut(board.D6)
button_alt.direction = Direction.INPUT
button_alt.pull = Pull.UP

button_ud = DigitalInOut(board.D5)
button_ud.direction = Direction.INPUT
button_ud.pull = Pull.UP

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

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

mods = [1, 2, 5, 10, -1, -2, -5, -10]

num = 0
m = 0
mod = mods[m]

toggle1 = 0
toggle2 = 0

while True:

    lcd.set_cursor_pos(0,0)
    lcd.print("Number: " + str(num))
    lcd.set_cursor_pos(1,0)