Joy-it RB-P-XPLR-SET handleiding

37 pagina's
PDF beschikbaar

Handleiding

Je bekijkt pagina 18 van 37
18
# Load libraries
from machine import Pin, SPI
import ST7735
import time
import lcd_gfx
# Initialization of GPIO16 as input and GPIO17 as output
trig = Pin(17, Pin.OUT)
echo = Pin(16, Pin.IN, Pin.PULL_DOWN)
# Initialize LCD
spi = SPI(0, baudrate=8000000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(19),
miso=Pin(16))
lcd = ST7735.ST7735(spi, rst=6, ce=17, dc=3)
backlight = Pin(2, Pin.OUT)
backlight.high()
lcd.reset()
lcd.begin()
lcd.ll_screen(lcd.rgb_to_565(255, 255, 255))
def translate(value, leftMin, leftMax, rightMin, rightMax):
# Figure out how 'wide' each range is
leftSpan = leftMax - leftMin
rightSpan = rightMax - rightMin
# Convert the left range into a 0-1 range (oat)
valueScaled = oat(value - leftMin) / oat(leftSpan)
# Convert the 0-1 range into a value in the right range.
return rightMin + (valueScaled * rightSpan)
# Endless loop for measuring the distance
while True:
# Distance measurement is started using the 10us trigger signal
trig.value(0)
time.sleep(0.1)
trig.value(1)
# Now wait at the echo input until the signal has been activated
# Then the time is measured for how long it remains activated
time.sleep_us(2)
trig.value(0)
while echo.value()==0:
pulse_start = time.ticks_us()
while echo.value()==1:
pulse_end = time.ticks_us()
pulse_duration = pulse_end - pulse_start
SUMMARY: In our first project, we measure distances with the ultrasonic sensor and visualize the measured distance by filling the graphic on the TFT display
to a greater or lesser extent. In our example, we fill the display completely from a measured distance of 100 cm.
Distance measurement
Auxiliary function for adjusting the
value range
Initialization of the ultrasonic
sensor and the TFT display

Bekijk gratis de handleiding van Joy-it RB-P-XPLR-SET, stel vragen en lees de antwoorden op veelvoorkomende problemen, of gebruik onze assistent om sneller informatie in de handleiding te vinden of uitleg te krijgen over specifieke functies.

Productinformatie

MerkJoy-it
ModelRB-P-XPLR-SET
CategorieNiet gecategoriseerd
TaalNederlands
Grootte21690 MB