We will show you how to shine the lights in Vector’s Cube at 6 different colors using the Anki Vector SDK in Python.
Anki Vector’s Cube
Vector has a cube that he can play with. The cube has lights which are RGB LEDs which can display multiple colors.
You have probably seen these lights turn on in Vector’s cube when he is doing his thing.
We will be writing a program so Vector’s cube can shine at different colors.
This is a fairly straight forward program that we’ll be writing. Let’s take a look at the commands we’ll be using.
- anki_vector.lights.red_light (as well as other colors)
Not a ton going on here. So we can jump in to the code.
Coding the Cube
Again this is a shorter program than usual. We wrote this with the Anki Vector SDK in Python.
We do the usual imports with anki_vector and time. However this time to keep things a little cleaner we did from anki_vector import lights.
The main function is called and we connect to the cube.
The colors are set. Currently I can only get the cubes to shine at these 6 colors instead of full Rainbow Cubes like with Cozmo.
We sweep through these 6 colors 5 different times, and we have Vector set the lights for his cube to those colors.
At the end, we make sure to turn the lights off on the cubes with cube.set_lights_off().
Here is the code:
""" Copyright Kinvert All Rights Reserved If you would like to use this code for business or education please contact us for permission at: www.kinvert.com/ Free for personal use """ import anki_vector from anki_vector import lights import time def main(): with anki_vector.Robot() as robot: print("It might take a while to connect to the Cube") while not robot.world.connected_light_cube: print("No Cube Yet...") robot.world.connect_cube() print("Connected") cube = robot.world.connected_light_cube colors = [ lights.red_light, lights.yellow_light, lights.green_light, lights.cyan_light, lights.blue_light, lights.magenta_light ] for j in range(5): for color in colors: cube.set_lights(color) time.sleep(0.25) cube.set_lights_off() time.sleep(0.5) if __name__ == "__main__": main()
Hopefully that makes sense. If not, you can always copy and paste the code to use it yourself.
Improving the Cube Code
One thing we will be doing is getting this to work as RGB.
In the past we made Rainbow Eyes for Vector With Hue. This is a little different than directly setting RGB values
We also looked at the pixels on Vector’s screen which is related to RGB. You can find that at https://www.youtube.com/watch?v=GvQWQ7OHVnw
As for the code, let’s look at a few other things.
How would you shine a white light?
What if you wanted the lights to shine a color for longer, or for less time?
Is there a way to make each corner of the cube a different color?
Beyond Vector’s Cube and Lights
If you found this interesting we write about a lot of similar stuff at Kinvert.
Finally, we have a mailing list with lots of great tips and tricks on Vector as well as Cozmo if you want. You can unsubscribe at any time.