I'm designing a college project. The project is an M&M's colour sorter using an arduino, an adafruit colour sensor, two inverter drives and two industrial servo motors. (Image in the link)
The motors each have a disk attached. The first disk has 8 holes evenly spaced around the edge. The idea is that as the disk rotates an M&M drops into the hole which is passed under the sensor. The arduino will give out a different digital output to the drive for each colour which will then spin the second disk to 1 of 6 angles to catch the correct colour in each cup.
The first colour is detected at 0 degrees as the disk spins clockwise the second colour is detected when the first colour is at 45 degrees, when the first colour reaches 90 degrees it falls through a hole into the cup and the third colour is detected.
The problem is that I need to delay the digital output for each colour until the next colour is detected as the second motor will move into position while the colour moving from 45 to 90 degrees.
So basically i want to output the signal for the first colour when the next colour is detected if this makes sense?
Does anybody have any suggestions about the best way to go about this in code?