Engduino Trail

 

1.First
Experience
2.Other
Examples
3.First
Sketch
4.Sketch
Explained

 

  

What is a sketch?

The Engduino was designed based on the open-source Arduino platform. There are many good guides and books that discuss programming on the Arduino and we will not seek to replicate them here.

However, to illustrate the structure of a sketch we will consider the following program:

#include <EngduinoLEDs.h>

void setup()
{
  EngduinoLEDs.begin();
}

void loop()
{
  EngduinoLEDs.setAll(BLUE);
  delay(500);
  EngduinoLEDs.setAll(OFF);
  delay(500); 
}

This program can be broken down into three parts:

Including headers

#include <EngduinoLEDs.h>

The first lines in the program contain the headers that can be included - these relate to the libraries that are going to be used in the following code. In this case, since we are intending to access the Engduino LEDs, we must include the appropriate header. We will discuss the other headers you might (also) include in the outline section on the library below.

You can also define global variables in this area of the code.

setup()

The setup routine is executed once when the program first starts to run. This happens (i) when the device is switched on; (ii) when a new upload has just been done; or (iii) or when the reset button has just been pressed.

 void setup()
{
  EngduinoLEDs.begin();
}

In this case, the only instruction in the setup function is to start the LED library running. If a library is loaded it MUST be started by calling the begin function before it can be used. If you do not call the begin routine, the remaining code will not work as you expect.

loop()

Finally, we come to the meat of the program. The loop function is called over and over again, as quickly as the Engduino can manage.

void loop()
{
  EngduinoLEDs.setAll(BLUE);
  delay(500);
  EngduinoLEDs.setAll(OFF);
  delay(500); 
}

In this case, the program sets all the LEDs on the Engduino to be blue, waits for 500ms (0.5 seconds) then switches them off and waits for the same time. The net result is that the LEDs flash on and off.

The full list of colours you might have chosen here is RED, GREEN, BLUE, YELLOW, MAGENTA, CYAN, WHITE and, although it's not strictly a colour, OFF. Experiment a little, and then we will look deeper into how you can control the Engduino.