Tiny Tesla Animated with AI

Tesla Model Pi (lol)

install LEDs and program a tiny Tesla to randomly use its turn signals and brake lights using a Pi Pico

I’ve had a project in my mind for a long time. I wanted to use Micropython and a Raspberry Pi Pico to animate LEDs. The LEDs would represent turn signals, headlights, tail lights, and brake lights - and illuminate in patterns to imitate a real car that was driving.


Alas, I am not the MOST skilled Python dev (read, total noob). So while I had all the necessary ingredients laying around, I never took the time to actually write the code.


Enter ChatGPT.

This new AI from OpenAI can do a pretty passable job at writing useful code. It’s not perfect, but it can get the job done with some help. Fortunately, I have been learning Python for about a year - so I was dangerous enough to know how to help ChatGPT help me.

I described what I wanted to do to the AI. I went through many iterations of this prompt, as it had unpredictable outcomes with the assumptions the AI would make.


Here’s what I ended up asking:

I have 6 LEDs I will use with a pi pico to animate lights on a scale model car. Here are the leds that I will be using: a. 1 headlight b. 1 tail light c. 1 yellow left turn signal (front) d. 1 yellow right turn signal (front) e. 1 left brake light (rear) (this also works as a left turn signal) f. 1 right brake light (rear) (this also works as a right turn signal) Here's what I want to code to do: -a and b should always be illuminated -while the code runs, I want these animations to happen randomly: animation 1: c and e flash together (0.5 seconds on, 0.25 seconds off) for a random amount of time between 3sec and 22sec. if this animation lasts longer than 3sec, illuminate f until animation ends animation 2: d and f flash together (0.5 seconds on, 0.25 seconds off) for a random amount of time between 3sec and 22sec. if this animation lasts longer than 3sec, illuminate e until animation ends animation 3: e and f illuminate together, staying on for a random amount of time between 1sec and 25sec please give this code in micropython, through animation 1, I will ask for the 2nd and 3rd animations separately


Lol.


That’s how it needed to hear the instructions. I still ended up customizing the code quite a bit. Check it out on my Twitter for video of it in action!


[affiliate links]

Here are the LEDs I used - choose from several different colors:

https://amzn.to/3hgZKyj


Here are some model cars that might make good donor units for such a project:

1/36 scale cars (you’ll probably have to remove the interior to fit the Pi Pico)


The Pi Pico is list price $4 - but if you want it super fast, Amazon has some for a few bucks more:

Amazon Picos


And finally, the code you’ll need. Note the pins assigned to the LEDs in the code when wiring it up.

carlights.py


installing some electrical tape to hold the lights in place, as well as prevent light bleed into the interior

If you build this project, or if you have questions, reach out to me on Twitter @chrisremboldt


Cheers!

Next
Next

You’ll Probably Buy a Humanlike Robot