LED colors vs history of mankind

Plenty of electronic devices (even those inexpensive from the Far East) have some kind of LEDs to indicate the state of the device. A good example may be a stand-by LED on the on-off switch of many TVs, another would be power-on LED on many laptop power supplies. Depends on a type of information, different color of LEDs are used.

Usually green color says that the device is in good state and don't need attention, it's the default color for power-on indicators. Yellow is used to indicate that there are some information or some events that the user may want to check, but they are not critical. Red color shows that something was wrong, that user should pay attention to the current state and maybe made some actions.

This is also a question of a good user interface, especially now, when everything tends to use white or blue LEDs - they are something fresh, something that wasn't available a decade ago. Yes, maybe they are cool, but they are also non-intuitive. That's a different story.

It may sound strange, but the selection of greed-yellow-red colors is not an accident, but is based on thousand of years of our human history. Green is intuitively connected with leafs, forest, bushes, trees - places to hide, that are much more secure than an open space. In open space, it's much easier to be observed by predators. Red is the color of fire - danger that kills and destroys, especially before human kind learned how to handle it. A lot of poisonous plants have red fruits too. Yellow is often a skin color of toxic animals that says "don't eat me, I'm toxic, you will die - I warned you". It's a color of information.

Even devices that cost tens of thousands of dollars have those LEDs that have a color selected just because thousands of years ago our ancestors were living like today monkeys and we still keep those references! That's amazing!

I think that if some day advanced alien race would get one of our electronic devices and reverse engineering it, they could understand what it is, why we use it and how it works. One thing that they wouldn't be able to understand would be why we choose those colors. That would be only possible if they would analyse our natural environment and our history.

It won't end, a lot of software applications also use those colors or have some widgets that simulate LEDs. In addition, sometimes there are also GUI widgets that simulates knobs, switches and other mechanical elements - maybe we live in an era that adds another level of this inheritance? What about floppy disc icon used as "Save as"? Who have a floppy disc, yet we still have this icon in many applications.

BTW, it's also interesting that e.g. traditional caliper works only because our eye and mind has great ability to misalignment among two line segments, however, we suck in different areas of image recognition (e.g. checking perpendicularity). An alien could analyze a caliper, but without knowledge of the biology of a human eye and human brain activity, it could be only possible to make assumptions why we are using calipers and not some other ways to measure distances.

3.3V to 30V DC/DC converter using SN6505A

Recently I'v got my samples of SN6505A, it's a really nice IC, so I decided to make a simple DC/DC converter to get familiar with it. What I like in this chip is that it can operate on input voltage as low as 2,5V - that makes it great for battery devices. It's also nice, that it's a very minimalist design - on primary side all what is needed is decoupling capacitor. One disadvantage is that it doesn't have a feedback loop.

To increase efficiency, SN6505A can operate with more developed versions of transformers, but I used the simplest configuration - one coil on each side. The circuit is presented below. The chip as well as other components is mounted on the bottom side of the PCB.

Current consumption is 330mA at 3V3, this could be probably easily reduced by using different transformator.

Unfortunately I din't have neither suitable transformer nor appropriate coil to wind it. I made my own transformator from a solenoid coil as a secondary side, and 10 loops of 0,7mm wire as a primary side. The inductances are respectively 2u5H and 11m5H. Maybe it's not the most beautiful transformer and EMI will be terrible, but for this simple project it works ok.

Summarizing, that's a nice chip and probably I will use it in some of my projects in the future.

How to check how many elements an array has?

In C it's possible to omit typing array size if it's fields are provided immediately, so the compiler can easily calculate the size by itself. This is presented below, note empty [] parenthesis.

    char* sampleArray[] = {
        "Hello world!",
        "How are you?",
        "You like coffe?"
    };

We can also specify the size directly:

    char* sampleArray[2] = {
        "Hello world!",
        "How are you?",
        "You like coffe?"
    };

Or use the best way:

    const int SampleArraySize = 2;

    char* sampleArray[SampleArraySize] = {
        "Hello world!",
        "How are you?",
        "You like coffe?"
    };

In the first two examples we don't have a variable that would tell us how many elements the array has. Sure, we may hardcode it, but it's not a good idea from a maintainability point of view.

We may calculate the size of above array by using a simple trick:

int sampleArrayLength = sizeof(sampleArray) / sizeof(sampleArray[0]);

Note that it will work with all built in types and if the size or even the type of an array will be changed in the future, this line will still be correct.

Below you may see a simple use case.

#include <stdio.h>


int main()
{
    char* sampleArray[] = {
        "Hello world!",
        "How are you?",
        "You like coffe?"
    };

    int sampleArrayLength = sizeof(sampleArray) / sizeof(sampleArray[0]);

    printf("someStrings array has %d  elments counting from one.\n", sampleArrayLength);

    for(int i = 0U; i < sampleArrayLength; i++)
    {
        printf("#%d element: %s\n", i, sampleArray[i]);
        
    }
    
    return 0;
}
sh-4.3$ main                                                                                                                                                                                                                                            
someStrings array has 3  elments counting from one.                                                                                                                                                                                                     
#0 element: Hello world!                                                                                                                                                                                                                                
#1 element: How are you?                                                                                                                                                                                                                                
#2 element: You like coffe?

Unfortunately, it will not work for arrays passed as pointers - for them, we need to pass size of an array as an additional argument.

How to check how many elements an enum has?

While C language doesn't offer build in method to check how many elements an enum has, it's still possible to obtain this information by using a simple trick.

The idea is to add a dummy element at the very end, since numeric enums values are 0, 1, 2, 3, 4, 5, ..., the numeric value of last element will be also the amount of elements that this enum has.

#include <stdio.h>

typedef enum Fruit {
    FRUIT_APPLE,
    FRUIT_ORANGE,
    FRUIT_BLACKBERRY,
    /* place new elements below */
    
    /* guard */
    FRUIT_LAST_ELEMENT
} Fruit;

int main()
{
    int fruitEnumLength = (FRUIT_LAST_ELEMENT - 1);
    printf("Fruit enum has %d elments counting from zero.\n", fruitEnumLength);

    return 0;
}
sh-4.3$ gcc -o main *.c                                                                                                                                                                                                                                 
sh-4.3$ main                                                                                                                                                                                                                                            
Fruit enum has 2 elments counting from zero.  

This technique may be useful for sanitizing input data or for writing tests.