Examples are great, but sometimes a tutorial is what the doctor ordered. In this tutorial, we’ll program two applications for Blinks, one that builds on the previous one. You should be able to follow the code line by line and hopefully learn a thing or two in the process.
/*
* Your very first Blinks application
*/
voidsetup(){
// this only happens once
}
voidloop(){
// this happens over and over again
// the rate can be variable, but it will happen at
// a maximum the refresh rate of the display (~66Hz)
}
Lets make a Blink blink!
create needed variables
Timer blinkTimer;
bool isBlinkOn;
initialize variables
voidsetup(){
blinkTimer.set(500);
isBlinkOn = false;
}
if the timer expires, update the status, on or off
/*
* Your very first Blinks application
*/
void setup() {
// this only happens once
}
void loop() {
// this happens over and over again
// the rate can be variable, but it will happen at
// a maximum the refresh rate of the display (~66Hz)
}
Lets make a Blink blink!
Timer blinkTimer;
bool isBlinkOn;
void setup() {
blinkTimer.set(500);
isBlinkOn = false;
}
void loop() {
if(blinkTimer.isExpired()) {
isBlinkOn = !isBlinkOn;
blinkTimer.set(500);
}
}
void loop() {
...
if(isBlinkOn) {
setColor(RED);
}
else {
setColor(OFF);
}
}
/*