#!/usr/bin/env python3 from machine import Pin, PWM import time color_r = [0, 0, 100, 100] color_g = [0, 100, 100, 0] red = Pin(16, Pin.OUT) green = Pin(17, Pin.OUT) pwm_r = PWM(Pin(16)) pwm_r.freq(1000) pwm_g = PWM(Pin(17)) pwm_g.freq(1000) pwm_r.duty_u16(0) pwm_g.duty_u16(0) def map(x, in_min, in_max, out_min, out_max): Y = int((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min) return Y def setColor(n): # For example : col = 0x1122 R_val = color_r[n] G_val = color_g[n] R_val = map(R_val, 0, 255, 0, 65535) G_val = map(G_val, 0, 255, 0, 65535) pwm_r.duty_u16(R_val) # Change duty cycle pwm_g.duty_u16(G_val) # --- Main Routine --- while True: for col in range(0,4): setColor(col) time.sleep(0.5)