Jump to content
THIS IS THE TEST SITE OF EUROBRICKS! ×
THIS IS THE TEST SITE OF EUROBRICKS!

Recommended Posts

Posted

I have been using, and having a lot of success with the EV3 micropython programming language. But, I need some help. I can display the the triplets for the rgb(). What I would like to do is be able to separate out the rgb() tuples into three separate variables so that I can use them to determine various colored pieces of paper. A sample code would be most appreciated.

Mike,

Posted (edited)

You can separate them with commands like AND and a bitshift.

AND is 1 if two input values are 1 (and not 0), otherwise the AND is 0 (0 AND 1 is 0, 1 AND 1 is 1, 0 AND 0 is 0).
bitshift shifts the values of a variable a given amount to the left or to the right (0001 lshift 1 is equal 0010 (or 0011, depending on the implementation))

A pseudo-code would be:

int rbg = 110011001100b    (4 bit R, 4 bit G, 4 bit B, the output of the sensor in binary. You have to check the actual datatype/ bitlength of the output)
int val2 = 000011110000b    (1 for the bits of G, again assuming that one r/g/b value is 4 bits long)
int val2 = rgb AND val2    (it should be a bitwise AND. Now the content of val2 is 000011000000)
int val2 = val2 rightshift 4    (Now the content of val2 is 000000001100, again assuming that one r/g/b val is 4 bits long)

I don't know if python supports binary inputs. You'd have to "convert" val2 to HEX if not.

The commands for rightshift and AND are probably not AND or rshift. You should be able to find them on your own ;)

Edited by Tcm0
Posted

I will see if I can find enough information with the micropython EV3 Lego documentation to try this. If not, maybe I can figure out how to do this from the micropython documentation. I was hoping for something along the lines like:

Rcolor = rgb(0)

Gcolor = rgb(1)

Bcolor = rgb(2)

Mike,

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...