1) First, Adding flashing text to the block of code until B2 is pressed?
Code: Select all
if button1_counter %2 == 0: #Pushed it twice kick to buzzer
lcd.clear() #Clear LCD screen
lcd.move_to(2,0) #Moves text 2 characters from left on row 1
lcd.putstr("INCOMPLETE CYCLE")
lcd.move_to(2,1) #Moves text 2 characters from left on row 2
lcd.putstr("PULL HANDLE DOWN")
lcd.move_to(0,3) #Moves text 0 characters from left on row 4
lcd.putstr("(CHECK ALL STATIONS)")
utime.sleep(0.5)
nasty_buzzer() #Sound buzzer because you pressed the button twice
button1_counter += 1 #Set counter to 1 incase pressed again
Below is my code so far... Thanks!
Code: Select all
import utime
import machine
from machine import I2C
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
I2C_ADDR = 0x27
I2C_NUM_ROWS = 4 #LCDs number of rows
I2C_NUM_COLS = 20 #LCDs number of columns
i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000)
lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
B1 = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN) #C to 3.3v, NO to GPIO 14
B2 = machine.Pin(15, machine.Pin.IN, machine.Pin.PULL_DOWN) #C to 3.3v, NO to GPIO 15
buzzer = machine.Pin(12, machine.Pin.OUT) #Red to GPIO 12 Black to Ground
button1_counter = 0
button2_counter = 0
def nasty_buzzer():
for i in range(10):
buzzer.value(1) #Start active buzzer
utime.sleep(0.5) #Pause 1/2 sec
buzzer.value(0) #Stop active buzzer
utime.sleep(0.5) #Pause 1/2 sec
#LCDs 4 rows are 0,1,2,3
lcd.clear() #Clear LCD screen
lcd.move_to(3,1) #Moves text 3 characters from left on row 2
lcd.putstr("LEE LOADMASTER")
lcd.move_to(3,2) #Moves text 3 characters from left on row 3
lcd.putstr("CONTROL PANNEL")
utime.sleep(4) #Pause for 4 seconds
lcd.clear() #Clear screen
lcd.move_to(2,1) #Moves text 2 characters from left on row 2
lcd.putstr("PULL HANDLE DOWN")
button1_counter += 1 #Sets button1 to 1 to show it was pressed on startup
button2_counter = 0 #Sets button2 to 0
utime.sleep(3) #Pause for 3 seconds
while True:
if B1.value(): #Was the B1 button pushed?
button1_counter += 1
button2_counter = 0 #Force the toggle (reset the other side)
if button1_counter %2 == 1: #Message head to button 2 on odd
lcd.clear() #Clear screen
lcd.move_to(2,1) #Moves text 2 characters from left on row 2
lcd.putstr("PULL HANDLE DOWN")
utime.sleep(0.5)
if button1_counter %2 == 0: #Pushed it twice kick to buzzer
lcd.clear() #Clear LCD screen
lcd.move_to(2,0) #Moves text 2 characters from left on row 1
lcd.putstr("INCOMPLETE CYCLE")
lcd.move_to(2,1) #Moves text 2 characters from left on row 2
lcd.putstr("PULL HANDLE DOWN")
lcd.move_to(0,3) #Moves text 0 characters from left on row 4
lcd.putstr("(CHECK ALL STATIONS)")
utime.sleep(0.5)
nasty_buzzer() #Sound buzzer because you pressed the button twice
button1_counter += 1 #Set counter to 1 incase pressed again
if B2.value(): #Was the B2 button pushed?
button2_counter += 1
button1_counter = 0 #Force the toggle (reset the other side)
if button2_counter % 2 == 1: #Message head to button 1 on odd pushes
lcd.clear() #Clear screen
lcd.move_to(3,1) #Moves text 3 characters from left on row 2
lcd.putstr("PUSH HANDLE UP")
utime.sleep(0.5)
if button2_counter %2 == 0: #Pushed it twice kick to buzzer
lcd.clear() #Clear LCD screen
lcd.move_to(2,0) #Moves text 2 characters from left on row 1
lcd.putstr("INCOMPLETE CYCLE")
lcd.move_to(3,1) #Moves text 3 characters from left on row 2
lcd.putstr("PUSH HANDLE UP")
lcd.move_to(0,3) #Moves text 0 characters from left on row 4
lcd.putstr("(CHECK ALL STATIONS)")
nasty_buzzer() #Sound buzzer because you pressed the button twice
button2_counter += 1 #Set counter to 1 incase pressed again