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¶
You have attempted of activities on this page