Skip to content

Instantly share code, notes, and snippets.

@xeecos
Created June 15, 2021 10:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xeecos/0a326e03f44633fed726867b0e71a3fe to your computer and use it in GitHub Desktop.
Save xeecos/0a326e03f44633fed726867b0e71a3fe to your computer and use it in GitHub Desktop.
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)
@partha-gapp
Copy link

Hi @xeecos , thank you for sharing these code examples. I was trying to get the RGB Led working with my mBot Mega. However. as per the mBot mega manual, the A13 and A14 pins are used for RGB Led lights (and not A10 as per this example).

In addition, I also found that the makeblock python module does not turn on the Led lights with set_colors () function for for the lights connected to the pin A13 (but it does work for A14 pin). Looking a the code, it appears that there is a logic in the rj25 modules that changes that port when the port is 67) ...please see attached.

Any help you can share is much appreciated.

I am using: Raspberry Pi 4, Python 3.7 and makeblock 0.1.7 with mBot Mega

JPEG image 3
JPEG image 4

modules (set_colors)

@WhereWereYouIn72
Copy link

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

@WhereWereYouIn72
Copy link

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