| « Analog input example for pyFirmata | pyFirmata GUI » |
Dimming a LED with pyFirmata
There are a lot of tutorials available for dimming a LED with sketches. My approach uses pyFirmata to do it.
import pyfirmata # Time (approx. seconds) to get to the maximum/minimum DURATION = 5 # Numbers of steps to get to the maximum/minimum STEPS = 10 # Creates a new board and define the pin board = pyfirmata.Arduino(/dev/ttyACM0) digital_0 = board.get_pin('d:11:p') # Waiting time between the wait_time = DURATION/float(STEPS) # Up for i in range(1, STEPS + 1): value = i/float(STEPS) digital_0.write(value) board.pass_time(wait_time) # Down increment = 1/float(STEPS) while STEPS > 0: value = increment * STEPS digital_0.write(value) board.pass_time(wait_time) STEPS = STEPS - 1 board.exit()
Download the commented and extended script from here.

