How to Code a Color Sorter in Modkit for Vex

by HamsterMan444 in Circuits > Sensors

519 Views, 0 Favorites, 0 Comments

How to Code a Color Sorter in Modkit for Vex

Screenshot 2020-11-25 163232.png

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)

Making the Sorter

Ball sorter.jpg

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.

Setting Up the Code

Screenshot 2020-11-25 165316.png

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.

Coding the Color Sensor

Screenshot 2020-11-25 170204.png

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.

Coding the Motor

Screenshot 2020-11-25 171457.png

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.

Capabilities

Screenshot 2020-11-25 172443.png
Picture1.jpg

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.

Programming the Robot

Screenshot 2020-11-25 174527.png
Screenshot 2020-11-25 174559.png

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

Nothin' else to it!

Thanks

Thanks all for reading!

Hope you found thins interesting!

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