8.1. Examples and scratchpad¶
Here are some example programs and a place to try them out; see also the reference manual.
8.1.2. Vary the brightness of the LED¶
Shake your device to make the LED light up!
import cellbotics
# Define the pin numbers we need.
LED1 = 2
# Select a PWM channel and configure the LED for PWM.
channel = 0
cb = cellbotics.CellBot()
cb.ledcSetup(channel, 1000, 16)
cb.ledcAttachPin(LED1, channel)
# Start the gyro.
gyro = cellbotics.Gyroscope()
gyro.start()
# Read the gyro and display it on the LED.
for i in range(20):
gyro_x2 = gyro.x**2
cb.ledcWrite(channel, min(2**16 - 1, gyro_x2*10000))
print(gyro_x2)
8.1.3. Your code¶
Not available.
Before you keep reading...
Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.
You have attempted 1 of 2 activities on this page