Advertisement
Guest User

Untitled

a guest
Mar 27th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. from machine import Pin, I2C
  2. import ssd1306
  3. from time import sleep
  4. import random
  5.  
  6. # ESP32 Pin assignment
  7. i2c = I2C(-1, scl=Pin(22), sda=Pin(21))
  8.  
  9. # ESP8266 Pin assignment
  10. #i2c = I2C(-1, scl=Pin(5), sda=Pin(4))
  11.  
  12. oled_width = 128
  13. oled_height = 64
  14. oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
  15.  
  16.  
  17. oled.text('Hello, World!', 0, 0)
  18.  
  19. oled.show()
  20. sleep(1)
  21. oled.fill(0)
  22. oled.show()
  23.  
  24. #Variables to display on screen1 (eg. sensor readings)
  25. #replace with your sensor readings
  26.  
  27. temp1 = random.randint(10,30)
  28. hum1 = random.randint(50,70)
  29. temp_f1 = temp1 * (9 / 5) + 32.0
  30.  
  31. #Rows to display on screen1
  32. #Prepare the rows you want to display on the screen - it must be a string
  33. screen1_row1 = 'Temp C: ' + str(temp1)
  34. screen1_row2 = 'Humidity: ' + str(hum1)
  35. screen1_row3 = 'Temp F: ' + str(temp_f1)
  36.  
  37. #Rows to display on screem 2
  38. screen2_row1 = 'Second screen'
  39. screen2_row2 = 'Second screen'
  40.  
  41. #create a list with lists for screen1
  42. #each list contains [x, y, message]
  43. screen1 = [[0, 0 , screen1_row1], [0, 16, screen1_row2], [0, 32, screen1_row3]]
  44. #create a list with lists for screen2
  45. screen2 = [[0, 0 , screen2_row1], [0, 16, screen2_row2]]
  46.  
  47.  
  48. #displays the screen
  49. def display_screen(screen):
  50. for i in range (0, oled_width+1, 4):
  51. for line in screen:
  52. oled.text(line[2], -oled_width+i, line[1])
  53. oled.show()
  54. if i!= oled_width:
  55. oled.fill(0)
  56.  
  57. def transition_screen(speed):
  58. for i in range ((oled_width+1)/speed):
  59. for j in range (oled_height):
  60. oled.pixel(i, j, 0)
  61. oled.scroll(speed+1,0)
  62. oled.show()
  63.  
  64. while True:
  65. display_screen(screen1)
  66. #screen1()
  67. sleep(5)
  68. transition_screen(2)
  69. #screen2()
  70. display_screen(screen2)
  71. sleep(5)
  72. transition_screen(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement