BEFORE YOU CONTINUE...

It is important to note that Chapter 2 will mainly comprise of tutorials regarding the Engduino components, which uses C code instead of Java code. However, C and Java languages are pretty much similar. Note that detailed understanding of how these components work will not be required for the Greenfoot game development. Hence, if you would like to jump straight into your game, head over to Chapter 3. However, if you wish to still wish to learn about the Engduino and its components (which would be really good for you!), then continue on. There will be challenges along the way, it is recommended to attempt them if you wish to deepen your understanding about how the Engduino components work. Solutions to the Challenge Yourself sections can be found here :- https://github.com/zhengonn97/engduinochallengesolutions

ENGDUINO LIBRARIES: THE LEDS

This is a quick guide to some of the things you can do with the LEDs. The LEDs can be set individually, or all together, and they can be set to different colours and brightnesses by mixing together different amounts of red, green and blue. There are 16 LEDs – and if you look on the board you’ll see their numbers (D0 – D15) written in white next to them.


  • HEADER

At the top of your program you must have the following line.

#include <EngduinoLEDs.h>

  • SETUP()

In the setup() function, you must have the following line.

EngduinoLEDs.begin();


  • BASIC FUNCTIONS

There are a number of functions that you can call to set the LEDs. The LEDs are numbered from 0 to

15 inclusive.

  • SET THE COLOUR OF ALL LEDS:

You can set the colour of all the LEDs at the same time. To set all the LEDs to the colour BLUE, at maximum brightness, we use:

EngduinoLEDs.setAll(BLUE);

The full set of colours available to you is RED, GREEN, BLUE, YELLOW, MAGENTA, CYAN, WHITE and,

although it's not strictly a colour, OFF.


  • CONTROLLING BRIGHTNESS

Maximum brightness is often a bit bright, so we can turn it down by selecting a number that ranges

from 0 (= off) to 15 (=brightest). To set the LEDs to a fairly dim YELLOW, we use:

EngduinoLEDs.setAll(YELLOW, 2);


  • SETTING A SINGLE LED

We can also set a colour for a single LED. For example to set LED 0 to be RED at maximum brightness we type:

EngduinoLEDs.setLED(0, RED);

But you can also control the brightness – to set LED2 to GREEN at brightness 3, then we use:

EngduinoLEDs.setLED(2, GREEN, 3);

Try this ‐ you should see that LED2 is a lot less bright than LED1.


  • MORE ADVANCED FUNCTIONS

The primary colours of light are red (R), green (G), and blue (B). If we mix these in different ways, we

can get all sorts of shades of light. The LED libraries allow users to set LEDs by the specific mix of

brightnesses of R, G, and B. Remembering that the brightness lies between 0 and 15:

Set all LEDs with red brightness = 2, green = 2; and blue = 0

EngduinoLEDs.setAll(2, 2, 0);

Red and green mixed together in equal proportions make yellow – so this is yellow and, because we

chose low numbers, it’s not very bright. But what if we want to make orange – which isn’t on our

original list? Well, orange is like yellow, but with a bit more red in it, so let’s make the red a bit

brighter and keep the green the same:

EngduinoLEDs.setAll(5, 2, 0);

Voila, orange.

We can do the same thing for individual LEDs. So, to set LED4 to a salmon pink (red = 9, green = 6,

blue = 2), we might use:

EngduinoLEDs.setLED(4, 9, 6, 2);


See if you can make an electronic candle where the top flickers, or any type of Christmas tree decoration!

results matching ""

    No results matching ""