Skip to content

Instantly share code, notes, and snippets.

@xeecos
Created Jun 15, 2021
Embed
What would you like to do?
RGB led
###USAGE###
# pip3 install makeblock --upgrade
###########
from time import sleep
from random import random
import math
from makeblock import MegaPi,SerialPort
A6 = 60
A7 = 61
A8 = 62
A9 = 63
A10= 64
A11= 65
A12= 66
A13= 67
A14= 68
A15= 69
megapi = MegaPi.connect() # or megapi = MegaPi.connect(SerialPort.connect("/dev/ttyXXXX"))
led = megapi.RGBLed()
j = 0
f = 0
k = 0
pixels = [0]*12
while(1):
for t in range(0,4):
pixels[t*3] = int(16 * (1 + math.sin(t / 2.0 + j / 4.0)))
pixels[t*3+1] = int(16 * (1 + math.sin(t / 1.0 + f / 9.0 + 2.1)))
pixels[t*3+2] = int(16 * (1 + math.sin(t / 3.0 + k / 14.0 + 4.2)))
led.set_colors(pixels,A10)
j += random()
f += random()
k += random()
sleep(0.01)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment