Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from machine import Pin, I2C
- import ssd1306
- from time import sleep
- import random
- # ESP32 Pin assignment
- i2c = I2C(-1, scl=Pin(22), sda=Pin(21))
- # ESP8266 Pin assignment
- #i2c = I2C(-1, scl=Pin(5), sda=Pin(4))
- oled_width = 128
- oled_height = 64
- oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
- oled.text('Hello, World!', 0, 0)
- oled.show()
- sleep(1)
- oled.fill(0)
- oled.show()
- #Variables to display on screen1 (eg. sensor readings)
- #replace with your sensor readings
- temp1 = random.randint(10,30)
- hum1 = random.randint(50,70)
- temp_f1 = temp1 * (9 / 5) + 32.0
- #Rows to display on screen1
- #Prepare the rows you want to display on the screen - it must be a string
- screen1_row1 = 'Temp C: ' + str(temp1)
- screen1_row2 = 'Humidity: ' + str(hum1)
- screen1_row3 = 'Temp F: ' + str(temp_f1)
- #Rows to display on screem 2
- screen2_row1 = 'Second screen'
- screen2_row2 = 'Second screen'
- #create a list with lists for screen1
- #each list contains [x, y, message]
- screen1 = [[0, 0 , screen1_row1], [0, 16, screen1_row2], [0, 32, screen1_row3]]
- #create a list with lists for screen2
- screen2 = [[0, 0 , screen2_row1], [0, 16, screen2_row2]]
- #displays the screen
- def display_screen(screen):
- for i in range (0, oled_width+1, 4):
- for line in screen:
- oled.text(line[2], -oled_width+i, line[1])
- oled.show()
- if i!= oled_width:
- oled.fill(0)
- def transition_screen(speed):
- for i in range ((oled_width+1)/speed):
- for j in range (oled_height):
- oled.pixel(i, j, 0)
- oled.scroll(speed+1,0)
- oled.show()
- while True:
- display_screen(screen1)
- #screen1()
- sleep(5)
- transition_screen(2)
- #screen2()
- display_screen(screen2)
- sleep(5)
- transition_screen(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement