Tutorial: How I made Orange


#1

I tried ORANGE as an input argument for the LED class methods and the compiler got mad at me. This was what I saw and it complained about orange was out of scope.

/Users/clara/Documents/Arduino/sketch_oct07a_orange/sketch_ oct07a_orange.ino: In function ‘void loop()’:
sketch_oct07a_orange:10: error: ‘ORANGE’ was not declared in this scope
led.turn_on_all(ORANGE);
^
exit status 1
‘ORANGE’ was not declared in this scope

I found out that scope is a namespace which is like a class roll at school. What this is saying is that Jane Smith exists but Oliva Smith does not exist. So I went to github Jewelbots repository to look at the ColorLabel enumerations in the header file LED_Colors.h and ORANGE was indeed not declared.

I thought to myself that if I want to make my favourite colour CYAN I would have to use a normal, everyday method, like turn_on_all(), flash_all() , etc. But what makes these methods work? Well, I learnt about the implementation cpp files are where we can find the brains of methods. So I went to the LED.cpp file and looked at the void LED::turn_on_single(LED_Pos led, ColorLabel color) and I discovered setLight() method was the thing that drove turn_on_single(). If you look further down in the file, you will find setLight () is also part of the LED class. Below is a snippet of the setLight method.

// Advanced feature - Use a custom RGB value
// input number is the LED position = (SE = 3, SW = 0, NW = 1, NE = 2)
// Each value of R, G, and B can each accept a value from 0 to 63 or 0x0 to 0x3F
void LED::setLight(uint8_t number, uint8_t r, uint8_t g, uint8_t b)

As you can see setLight has 4 values to input. The first one is your LED position but instead of putting in letters you have to put in numbers. Then the r, g, b stand for red, green and blue and you have to put an in uint8_t value which is an integer. If you put in random numbers you will get a colour. So I looked up a colour chart at http://rapidtables.com/web/color/RGB_Color.htm to find out what 3 integers make up ORANGE.

I tried many combinations and the best combination I had was 255, 126, 0 but the colour was really dim. I also tried the combination from the Animation::rainbows.led_cmd_t but it didn’t look very orange to me. With a bit of luck, I stumbled upon the perfect combination 83, 4, 0 on the Arduino forum.

The End.:smile_cat:


#2

This is so great, thank you!!! Would you mind if we added this as a blog post?


#3

Not at all. Feel free to upload it to the blog. :smile_cat:


#4

So cool! Thank you!


#5

This helps me! Thank you!