How to Code a Color Sorter in Modkit for Vex

Introduction: How to Code a Color Sorter in Modkit for Vex

Hi all,

In this tutorial you will learn how to code a color ball sorter in Modkit for Vex

Hope you make it and enjoy!

Pls vote for me! :)

Supplies

a computer

Modkit for Vex: https://www.modkit.com/vex/editor/

Vex IQ kit

Vex colored balls (White and Black)

Step 1: Making the Sorter

This isn't technically code so i'll just add a pic in and tell you how it works

The balls come in the front, pass over the color sensor, telling the motor which way to turn, putting the balls onto different paths.

Step 2: Setting Up the Code

First you must drag-and-drop a color sensor and a motor. Make sure the color sensor is set to the grey scale mode. You can select any port for the components.

Step 3: Coding the Color Sensor

This is all the code for the color sensor.

The 0.2 second wait at the beginning is to let the color sensor start up properly.

The first 'if' statement is to distinguish if the ball is white. If the color sensor detects a grey scale percentage of greater than 20%, the ball is white and it will print this on the brain's screen.

The second 'if' statement is to distinguish if the ball is black. If the color sensor detects a grey scale percentage of less than 4%, the ball is black and it will print this on the brain's screen.

Step 4: Coding the Motor

The motor code is very similar to the color sensor code.

The only difference is that it doesn't print onto the brain, rather, it spins the motor in different directions according to the color.

This piece of code might have to be altered depending on how the sorter was made in the first place. I attached the motor with a connector that had just enough friction to move the paddle (the thing that turns to make the balls go different ways) but if it had any resistance, the motor could spin without moving the paddle. This means that the motor can keep spinning even after the paddle has gone as far as it can.

It also helps in that when two of the same color balls are put through, the motor can sense both balls, turn the motor twice, and not break any pieces.

Step 5: Capabilities

This is a robot that I have been working on.

It's essentially the ball sorter on wheels with a blade at the front to get the balls into the sorter and a catcher on the back.

Step 6: Programming the Robot

Select which slot you want to download to, then hit the program button.

Nothin' else to it!

Step 7: Thanks

Thanks all for reading!

Hope you found thins interesting!

Vote, comment, and favorite if you want to see more like this! :)

Block Code Contest

Participated in the
Block Code Contest

Be the First to Share

    Recommendations

    • Lamps Challenge

      Lamps Challenge
    • Puzzles Challenge

      Puzzles Challenge
    • CNC and 3D Printing Contest

      CNC and 3D Printing Contest

    Comments