===== LED dimmer ===== This example shows how to fade-in and fade-out a red LED by using PWM output. ==== Requirements: ==== * Uper1 board ==== Code: ==== from time import sleep from IoTPy.pyuper.uper import UPER1 with UPER1() as board, board.PWM(27) as redPin: redPin.set_frequency(1000) while True: for i in xrange(0, 100): redPin.set_duty_cycle(i) sleep(0.01) for i in reversed(xrange(0, 100)): redPin.set_duty_cycle(i) sleep(0.01) ===== Color spinner ===== This example shows how three PWM channels can be combined to create a visually nice color spinner. ==== Requirements: ==== * Uper1 board ==== Code: ==== from colorsys import hls_to_rgb from time import sleep from IoTPy.pyuper.uper import UPER1 with UPER1() as board, \ board.PWM(27, polarity=0) as redPin,\ board.PWM(28, polarity=0) as greenPin,\ board.PWM(34, polarity=0) as bluePin: while True: for color in xrange(500): rgb = hls_to_rgb(color*0.002, 0.1, 1) redPin.set_duty_cycle(rgb[0]*100) greenPin.set_duty_cycle(rgb[1]*100) bluePin.set_duty_cycle(rgb[2]*100) sleep(0.002)