RGB Animation: Part 1 - Breathing

Introduction

Nowadays, RGB (red, green, blue) lighting is everywhere. It’s in your phone’s notification light, your screen, and inside computer chassis. In this project we will be learning how to make some common RGB lighting animations on our neopixel. 

 

For this first part, we will make a simple one that gradually goes bright and then gradually turns off.

Components Needed

  • Little Python Brain
  • A tablet/phone/laptop
Steps

1

Importing and setup

We will need to setup the neopixel. We also need to import the sleep element.

2

The first for loop

A neopixel takes a value of a color brightness from 0 to 255. Each of the (255, 255, 255) in the default block signifies a color: red, green, and blue.

For this loop, we will just make red color gradually go brighter. 

Note that in this for loop, the first iteration would be i = 0 while the last iteration is i = 255. We specify the “end” as 256 because we want our loop to go up until the very last number BEFORE 256, which is 255.

Finally, make sure to add a sleep after np.write(). A sleep duration of 0.01 seconds will do.

3

The second for loop

Once the first for loop has finished, we will then have a very bright red neopixel. We then want to do the opposite of the first for loop: we will gradually make the color dimmer.

For this, simply add a sleep(1) block after the first for loop then duplicate the first for loop and place it after that sleep(1) block.  

Afterwards, we only need to change the parameters of the second for loop so that it starts at 255 (which we left off in the previous for loop) and ends at -1 (meaning that the loop goes all the way to i = 0) with a step of -1 (meaning that it goes BACK 1 step instead of going FORWARD 1 step)

4

Making the while True loop

Finally, add a sleep(1) block after the second for loop then drag the two for loops inside a while True block. Run the code!

The Complete Code

Run this code and try to change the i to either the green and blue RGB values! 

Back to: Intermediate > RGB Lighting
© 2020 Little Python

CONTACT US

    Log in with your credentials

    or    

    Forgot your details?

    Create Account