EasyManua.ls Logo

Makeblock mBot2 - CyberPi Advanced Features; Extra Sensor and Input Usage; Light Sensor Measurement; Sound Sensor Measurement

Makeblock mBot2
22 pages
Print Icon
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
22 | P a g e
Appendix 1 CyberPi Extras
Ultrasonic, slider (potentiometer) and multi-touch
import cyberpi as cpi
import time
while True:
distance = cpi.ultrasonic2.get(index=1)
pot = cpi.slider.get()
touch = cpi.multi_touch.is_touch(ch = 1) #1-8 or ch = "any"
print(distance, pot, touch)
time.sleep(0.1)
Light sensor
light = cpi.get_bri()
Sound sensor
volume = cpi.get_loudness(mode = "maximum")
Audio Commands
cpi.audio.play_tone(freq, t)
cpi.audio.add_vol(val) #-100 100
Accelerometer/Gyro Commands
forward = cpi.is_tiltforward()
backward = cpi.is_tiltback()
left = cpi.is_tiltleft()
right = cpi.is_tiltright()
cpi.is_shake()
cpi.get_shakeval() #0-100
cpi.get_pitch() #pitch angle
cpi.get_roll() #roll angle
cpi.get_yaw() #yaw angle
cpi.reset_yaw()

Related product manuals