Guest User

Untitled

a guest
Oct 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. from RPLCD import CharLCD, cleared, cursor
  2. import RPi.GPIO as GPIO
  3. import time
  4. from gpiozero import Button
  5. GPIO.setmode(GPIO.BCM)
  6. GPIO.setup(5, GPIO.OUT)
  7. GPIO.setup(22, GPIO.OUT)
  8. GPIO.setup(17, GPIO.OUT)
  9. GPIO.setup(27, GPIO.OUT)
  10. GPIO.setup(12, GPIO.OUT)
  11. GPIO.setup(25, GPIO.OUT)
  12. GPIO.setup(24, GPIO.OUT)
  13. GPIO.setup(23, GPIO.OUT)
  14. GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
  15. GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
  16. GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
  17. GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
  18.  
  19. lcd = CharLCD(numbering_mode=GPIO.BCM, cols=16, rows=2, pin_rs=13,
  20. pin_e=6, pins_data=[5,22,17,27,12,25,24,23])
  21.  
  22. Nbutton = Button(19, pull_up=False, bounce_time=0.001)
  23. Ubutton = Button(26, pull_up=False, bounce_time=0.001)
  24.  
  25. def Fruits():
  26. lcd.cursor_pos = (0, 0)
  27. lcd.write_string("Fruits-1")
  28. lcd.cursor_pos = (1, 0)
  29. lcd.write_string("Fruits-2")
  30.  
  31. def Vegetables():
  32. lcd.cursor_pos = (0, 0)
  33. lcd.write_string("Vegetables-1")
  34. lcd.cursor_pos = (1, 0)
  35. lcd.write_string("Vegetables-2")
  36.  
  37. def Clothes():
  38. lcd.cursor_pos = (0, 0)
  39. lcd.write_string("Clothes-1")
  40. lcd.cursor_pos = (1, 0)
  41. lcd.write_string("Clothes-2")
  42.  
  43. def Shoes():
  44. lcd.cursor_pos = (0, 0)
  45. lcd.write_string("Shoes-1")
  46. lcd.cursor_pos = (1, 0)
  47. lcd.write_string("Shoes-2")
  48.  
  49. count=0
  50. try:
  51. while 1:
  52. for count in range(0,4):
  53. Nbutton.wait_for_press()
  54. count = count +1
  55. print (count, "presses so far")
  56. if count == 1:
  57. Fruits()
  58. elif count == 2:
  59. Vegetables()
  60. elif count == 3:
  61. Clothes()
  62. elif count == 4:
  63. Shoes()
  64. else:
  65. pass
  66. time.sleep(0.3)
  67.  
  68. except:
  69. pass
  70.  
  71. finally:
  72. lcd.clear()
  73. GPIO.cleanup()
Add Comment
Please, Sign In to add comment