import time
import lcdlib as lcd

LCD_LINE_1 = 0x80  # LCD RAM address for the 1st line
LCD_LINE_2 = 0xC0  # LCD RAM address for the 2nd line

# Initialise display
lcd.init(25, 24, 23, 17, 18, 22, 16)

while True:
    # Send some test
    lcd.string("Rasbperry Pi", LCD_LINE_1)
    lcd.string("16x2 LCD Test", LCD_LINE_2)

    time.sleep(3)  # 3 second delay

    # Send some text
    lcd.string("1234567890123456", LCD_LINE_1)
    lcd.string("abcdefghijklmnop", LCD_LINE_2)

    time.sleep(3)  # 3 second delay
示例#2
0
    pulse_duration_3 = pulse_end_3 - pulse_start_3
    #speed = distance/duration
    #duration = pulse_duration/2 (we need only the distance to the object
    #speed of sound = 343 m/S = 34300 cm/S
    distance_3 = (pulse_duration_3 * 34300) / 2
    #round the distance to 2 decimal
    distance_3 = round(distance_3, 2)
    print("Distance 3:", distance_3, "cm")

    return distance_3


############### LCD display #####################

#initialize lcd pins
lcd.init(26, 19, 13, 6, 5, 11, 16)
# 80 : Hexadecimal code use to force cursor to beginnig at first line
LCD_LINE_1 = 0 * 80

#////////////////////#
while True:
    client = mqtt.Client()

    # set username and password
    client.username_pw_set("wdvebxdg", "QMlVLEusK9yU")

    client.on_publish = on_publish
    client.on_connect = on_connect

    client.connect(mqtt_server, port=12313, keepalive=60)
    client.loop_start()