Brodcast/Recive/Unpack of detected Color #2418
Unanswered
konrad20100
asked this question in
Q&A
Replies: 3 comments
-
Beta Was this translation helpful? Give feedback.
0 replies
-
|
V V ned., 2. nov. 2025 ob 22:35 je oseba David Lechner <
***@***.***> napisala:
… Which BLOCK can I use to convert detected color to a number?
I found a completely not obvious way to do this. 🤓
pybricks_program_2025-11-02T21_27_41.png (view on web)
<https://github.com/user-attachments/assets/27ab42dd-fd84-4727-8e07-6bb2440d41d2>
The Color type is iterable, which means we can put it in a for loop and
it will loop 3 times, once with the hue, once with the saturation and once
with the value. The hue represents the actual color, so that is the only
value we really need. So we can just return from inside the loop to get the
first value. The loop won't run any more since we returned.
We can put that in a task to make it reusable and then use it to convert a
color to a number.
This program outputs:
Color.RED is 0Color.GREEN is 120Color.BLUE is 240
How do I create a BROADCAST LIST?
The broadcast block in the palette already has a list in it.
image.png (view on web)
<https://github.com/user-attachments/assets/4a46f8e3-1b98-400a-b50c-3e15be23a4f2>
Do I need a separate BROADCAST LIST for each color or one LIST for all 4
colors?
If you can only detect one color at a time (because there is only one
color sensor), then you only need to send that one color. You can delete
the list and just put the color in the broadcast block.
—
Reply to this email directly, view it on GitHub
<#2418 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BUNVPNNMXDCLF5BHNASNTKD32ZTJFAVCNFSM6AAAAACK5QMLDGVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTIOBVGMYDSOI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Hi. I tried a few times, I'm not doing something right....
What exactly should I put in UNPACK: block OBSERVE or block READ ?
I hope I didn't ruin your Friday afternoon... |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


Uh oh!
There was an error while loading. Please reload this page.
-
Dear experts
I have to do a school project, with 5 hubs (with Pybrics-blocks).
Task:
A car made from Lego brics (hub A) has to do some path and drive onto a conveyor belt. The color sensor (on Hub B) has to determine the color of the car (Yellow, Red, Blue or Green) and BRODCAST data.
Hub C should RECIVE/UNPACK data and, moves the conveyor belt to the appropriate position (motor rotation for 360, 720, 1080 or 1440°).
HUB B BRODCAST data that the conveyor belt has finished.
Then the car (HUB A) should RECIVE/UNPACK data and drives into the appropriate garage.
I have assembled the model, but I can't make a working program.
I found information on GitHub that it is not possible to broadcast color data, but it is necessary to convert the color in to a number (Yellow=1, R=2, B=3 and G=4....).
Which BLOCK can I use to convert detected color to a number?
How do I create a BROADCAST LIST? Do I need a separate BROADCAST LIST for each color or one LIST for all 4 colors?
I wanted to use the tutorials https://www.youtube.com/watch?v=WzmcihSV2YE or https://www.youtube.com/watch?v=liv37b7PXUQ as a basis, but they don't help me.
It is working with reflected light, ambient light, force sensor, ulttrasonic sensor, bat not with color detection (standard lego color) . I spend whole halloween weekt for this task,.. I'm down, and I'm running out of time.
Does Pybrics comunity have any video or text tutorials regarding this topic?
Maybe I just didn't search on adequate folders or pages.
Regards
K
Beta Was this translation helpful? Give feedback.
All reactions