You must first complete RGB Animation: Part I – Breathing Animation before viewing this Lesson

RGB Animation: Part 2 - Color Cycle

Introduction

We will now apply what we learned on Part 1 to create a color cycle that fades across all the colors in the neopixel.

Components Needed

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

1

Inversely proportional relationships

For the colors to cycle through red, green, and blue, we want to make a code that utilizes a basic inversely proportional relation. 

Simply put, as one goes higher (i), the other one decreases (255-i).

This means that when i = 0,

Red is 255 and Green is 0

And when i = 255,

Red is 0 and Green is 255.

2

More for loops

Simply copy the for loop above a couple of times and do one that changes from red to green, from green to blue, and finally from blue to off. 

The Complete Code

Try changing around the sleep duration to observe different speeds

Back to: Intermediate > RGB Lighting

CONTACT US

    Log in with your credentials

    or    

    Forgot your details?

    Create Account