Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from RPLCD import CharLCD, cleared, cursor
- import RPi.GPIO as GPIO
- import time
- from gpiozero import Button
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(5, GPIO.OUT)
- GPIO.setup(22, GPIO.OUT)
- GPIO.setup(17, GPIO.OUT)
- GPIO.setup(27, GPIO.OUT)
- GPIO.setup(12, GPIO.OUT)
- GPIO.setup(25, GPIO.OUT)
- GPIO.setup(24, GPIO.OUT)
- GPIO.setup(23, GPIO.OUT)
- GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
- GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
- GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
- GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
- lcd = CharLCD(numbering_mode=GPIO.BCM, cols=16, rows=2, pin_rs=13,
- pin_e=6, pins_data=[5,22,17,27,12,25,24,23])
- Nbutton = Button(19, pull_up=False, bounce_time=0.001)
- Ubutton = Button(26, pull_up=False, bounce_time=0.001)
- def Fruits():
- lcd.cursor_pos = (0, 0)
- lcd.write_string("Fruits-1")
- lcd.cursor_pos = (1, 0)
- lcd.write_string("Fruits-2")
- def Vegetables():
- lcd.cursor_pos = (0, 0)
- lcd.write_string("Vegetables-1")
- lcd.cursor_pos = (1, 0)
- lcd.write_string("Vegetables-2")
- def Clothes():
- lcd.cursor_pos = (0, 0)
- lcd.write_string("Clothes-1")
- lcd.cursor_pos = (1, 0)
- lcd.write_string("Clothes-2")
- def Shoes():
- lcd.cursor_pos = (0, 0)
- lcd.write_string("Shoes-1")
- lcd.cursor_pos = (1, 0)
- lcd.write_string("Shoes-2")
- count=0
- try:
- while 1:
- for count in range(0,4):
- Nbutton.wait_for_press()
- count = count +1
- print (count, "presses so far")
- if count == 1:
- Fruits()
- elif count == 2:
- Vegetables()
- elif count == 3:
- Clothes()
- elif count == 4:
- Shoes()
- else:
- pass
- time.sleep(0.3)
- except:
- pass
- finally:
- lcd.clear()
- GPIO.cleanup()
Add Comment
Please, Sign In to add comment