main.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. """
  2. Author: Tobias Müller
  3. Date: 30.06.2023
  4. Version: 1.0
  5. Main File to run on the pico.
  6. """
  7. ############################## Modules ##############################
  8. from Libs.LCD_Shield import LCD
  9. from time import sleep_us
  10. from machine import Pin
  11. ############################## Global Variables ##############################
  12. Display = LCD()
  13. ############################## Main ##############################
  14. def main():
  15. """
  16. Main Program
  17. """
  18. ########################## Local Variables ############################
  19. button_up = Pin(6,Pin.IN,Pin.PULL_DOWN)
  20. button_down = Pin(7,Pin.IN,Pin.PULL_DOWN)
  21. button_right = Pin(8,Pin.IN,Pin.PULL_DOWN)
  22. button_left = Pin(9,Pin.IN,Pin.PULL_DOWN)
  23. led_green = Pin(16,Pin.OUT)
  24. led_red = Pin(17,Pin.OUT)
  25. ########################## Code ############################
  26. led_green.on()
  27. led_red.on()
  28. Display.lcd_line_mode = 3
  29. Display.print("Hochschule Anhalt")
  30. for _ in range(0,3):
  31. for brightness in range(0,105,5):
  32. Display.lcd_brightness = brightness
  33. sleep_us(25000)
  34. for brightness in range(0,105,5):
  35. Display.lcd_brightness = 100 - brightness
  36. sleep_us(20000)
  37. Display.clear()
  38. Display.print("LCD Shield testing:")
  39. for brightness in range(0,105,5):
  40. Display.lcd_brightness = brightness
  41. sleep_us(20000)
  42. sleep_us(2000000)
  43. while True:
  44. if button_up.value():
  45. Display.clear()
  46. Display.lcd_line_mode = 0
  47. Display.print("button", row=1)
  48. Display.print("up *", row=2)
  49. Display.print("* *", row=3, column=7)
  50. Display.print("*", row=4, column=8)
  51. led_red.off()
  52. sleep_us(300000)
  53. Display.clear(row=2, column=8)
  54. led_red.on()
  55. sleep_us(300000)
  56. elif button_down.value():
  57. Display.clear()
  58. Display.lcd_line_mode = 0
  59. Display.print("button down * * * *")
  60. led_green.off()
  61. sleep_us(300000)
  62. Display.clear(row=4)
  63. led_green.on()
  64. sleep_us(300000)
  65. elif button_left.value():
  66. Display.clear()
  67. Display.lcd_line_mode = 0
  68. Display.print("button", row=1)
  69. Display.print("left *", row=2)
  70. Display.print("* *", row=3, column=7)
  71. Display.print("*", row=4, column=8)
  72. led_green.off()
  73. led_red.on()
  74. sleep_us(300000)
  75. Display.clear(row=3, column=7)
  76. led_green.on()
  77. led_red.off()
  78. sleep_us(300000)
  79. elif button_right.value():
  80. Display.clear()
  81. Display.lcd_line_mode = 0
  82. Display.print("button\nright *\n * *\n *")
  83. led_green.off()
  84. led_red.off()
  85. sleep_us(300000)
  86. Display.clear(row=3, column=9)
  87. led_green.on()
  88. led_red.on()
  89. sleep_us(300000)
  90. else:
  91. Display.clear()
  92. Display.lcd_line_mode = 2
  93. led_red.on()
  94. led_green.on()
  95. Display.print("LCD Shield")
  96. Display.print("a button", row=3, column=2)
  97. for pattern in range(0,9):
  98. if pattern == 0:
  99. Display.print(" push ", row=2)
  100. elif pattern == 1:
  101. Display.print("> push <", row=2)
  102. elif pattern == 2:
  103. Display.print(">> push <<", row=2)
  104. elif pattern == 3:
  105. Display.print(">>>push<<<", row=2)
  106. elif pattern == 4:
  107. Display.print(" >>push<< ", row=2)
  108. elif pattern == 5:
  109. Display.print(" >push< ", row=2)
  110. elif pattern == 6:
  111. Display.print(" push ", row=2)
  112. else:
  113. Display.clear(row=2)
  114. sleep_us(100000)
  115. ############################## Run ##############################
  116. if __name__ == "__main__":
  117. main()