Created
June 15, 2021 10:23
-
-
Save xeecos/0a326e03f44633fed726867b0e71a3fe to your computer and use it in GitHub Desktop.
RGB led
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###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) |
Just an update from my experience that may help others.
I found that the A13 RGBLED does work and it's the A14 RGBLED that doesn't. I'm not currently using any of the other devices connected to A6 thru A15 so, I moved the RGBLED from A14 to A12 and now both RGBLEDs work fine.
Note that I am using the "Firmware for Megapi" version 0e.01.018. I've downloaded the source ( https://github.com/Makeblock-official/Makeblock-Libraries/blob/master/examples/Firmware_for_MegaPi/Firmware_for_MegaPi.ino ), compiled it (via the Arduino IDE) and uploaded it to the mBot Mega.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, I'm excited to see your post, I'm also trying to control an mBot Mega with a Pi 4 (via USB). The results I'm getting are very inconsistent and the makeblock support seems light to non-existent. Are you still working on this? I'd appreciate any insights that you might have. TIA, Ken