DUE BrainBot Flashy

DUE BrainBot Flashy

The BrainBot is equipped with two headlights and two taillights. The headlights work in tandem together and can’t be controlled individually. The taillights, however, work independently.

Prerequisite

This lesson assumes you’ve already assembled your BrainBot, followed by the BrainBot Intro.

Headlight

To set the headlights we use the HLit() function, which uses variable C for color. What color do we want to use? The color value is standard and used everywhere around the web. Search “color picker” and you will find many options. We need the HEX value of the color. Sometimes this value has a hash symbol (#) by it. The number is always 6 characters, each 2 characters represent a color: Red, Green, and Blue. Did you know you can make any color using just RGB?

Let us set the color to what we have picked. Note that hex numbers in DUE proceed with 0x.

C = 0x6a8a21
HLit()

Let’s Change the headlights to full red.

C = 0xFF0000
HLit()

Here is another example!

Let’s make the headlights purple using the HEX value.

C = 0x800080
HLit()

We can use a loop to make the headlights flash between red & blue.

@Loop
    C = 0xFF0000
    HLit()
    Wait(500)
    C = 0x0000FF
    HLit()
    Wait(500)
Goto Loop

Taillights

The BrainBot has two independent taillights. We can control them individually using the TLit() function. The color for the taillights are held in the x and y variables. Just like with headlights, we can set these lights (LEDs) to any color.

Let’s Flash the taillights like we did the headlights inside a loop.

@Loop
    X = 0xFF0000
    Y = 0x0000FF
    TLit()
    Wait(500)
    X = 0x0000FF
    Y = 0xFF0000
    TLit()
    Wait(500)
Goto Loop


What’s Next?

Let’s move on to BrainBot Collision to help our robot avoid hitting everything in it’s path.

BrainStorm

Why are colors represented in HEX? Since every color is a single byte, the range for each color is 0 to 255. If you didn’t know, a byte is 8 bit and 2 to the power of 8 is 255. What happens when we use a number higher than 255? And how do we show the value? 255255255? All this is representation to us humans. The computer internally is all binary (zeros and ones). A HEX number is easier for us to see and manage. A number of 5577DD is HEX is easy to see that it is 3 bytes (each byte is always 2 digits) and in the case of RGB color, we can easily see that green is 77 in this example.

Content Licensing
Newsletter

Twitter Feed
Hot off the press!
January 30, 2024
December 14, 2023
December 11, 2023
December 8, 2023
November 24, 2023