THIS PAGE IS UNDERGOING CHANGES - PLEASE RETURN SHORTLY
This series of videos and exercises are designed to develop learners' Arduino C programming skills.
If you are new to Arduino C, we would recommend that you complete our online Introduction to Arduino C and Programming a Self-Driving Robot series first.
Select a session heading to get started.
Tinkercad is a free in browser software that allows users to build and program simulated circuits using a selection of micro-controllers.
You will need an account, these are free to register, or you can sign in using an existing Google, Apple, Microsoft, or Facebook account.
We have made our NeoMatrix simulated circuit available for these activities.
This file also includes a program for set-up - as Tinkercad cannot access the NeoMatrix library, the functions it contains have been pre-written into the code.
For more information regarding how to use Tinkercad, please visit our Online Electronics Series.
We have put together a set of exercises for you to get started with programming a simulated NeoMatrix in Tinkercad.
All learners should start with the bronze level and work their way up as far as they can.
Click on each challenge heading to expand.
The program we provide with the circuit includes the libraries and NeoMatrix set-up.
randomColor
, but it is incomplete. Can you make it so that this function generates a random output value for the brightness of the red, green, and blue outputs?
Tip: The lower and upper variables have already been set in the function's parameters.
r
, g
, and b
and set them to zero.
random()
function (already created as part of one of the libraries) for each colour's variable.
random()
function should be set to match the variables created inside the randomColor()
parameters.
r = random(lower, upper);
g
and b
.
uint16_t randomColor(uint8_t lower=0, uint8_t upper=255)
{
uint8_t r,g,b = 0;
r = random(lower, upper);
g = random(lower, upper);
b = random(lower, upper);
return matrix.Color(r, g, b);
}
Tip: Use the return
command at the end, not matrix.show()
. You should only use the show command inside the void loop()
.
matrix.fillScreen()
function (this is included in the libraries already added).
randomColor()
function from inside the brackets of the matrix.fillScreen()
command.
For our answer program, we have called this new function 'randomFill'.
void randomFill()
{
matrix.fillScreen(randomColor());
}
matrix.fillRect()
command from the void loop()
to a new function called 'redSquare'. Then, delete the rest of the void loop()
program.
The new function:
void redSquare()
{
matrix.fillRect (1, 1, 6, 6, matrix.Color(255, 0, 0));
}
The void loop()
:
void loop()
{
}
void loop()
, start a new program that does the following;
matrix.Clear()
function from the supplied libraries to clear the screen.
matrix.show()
function is called to refresh the matrix and display the current programmed image.
void loop()
{
matrix.clear();
randomFill();
matrix.show();
delay(1000);
}
/**
and */
) to document (make notes on) your functions as a reminder of what they do, what the parameters are, and why. This will make it easier for you to understand when you look back through your code later.
/** This function is a random colour generator for RGB pixels/LEDs.
The minimum brightness is 0 and the maximum is 255.
The function has local variables for the RGB values as well as the lower and upper limits of the brightness.
The lower and upper varaibles are created and set inside the function's parameters.*/
This continues to build on the same program.
Tip: You already have a redSquare()
function you can look at for guidance, as well as the video for this session.
void loop()
program. Remember, you will need to clear the matrix before adding this new section of program.
This continues to build on the same program.
Tip: This will require a nested for-loop.
void loop()
, with screen clearings and pauses where needed.
Here are some suggestions of other things you could attempt at this stage.