-
Notifications
You must be signed in to change notification settings - Fork 0
Blink
Guilherme Lima Bernal edited this page Aug 8, 2014
·
5 revisions
This example is based on http://arduino.cc/en/Tutorial/Blink
This demonstrates how to make a LED blinker. You can use any pin to connect the LED, but here we will use the builtin LED that all Arduino boards have (usually pin 13). Instead of forcing you to manage pins directly, Highino provides you classes for the most common peripheral, such as the LED. Obviously you also have the Pin class and can deal with it directly. Led is implemented on top of it.
Notice that we pass the pin number as a template argument. This allows the compiler to deduce a lot of information at compile-time, while the Arduino library does so at run-time wasting time and memory.
##Arduino
int led = 13; // give a name to the pin 13
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}Binary size: 1551 bytes.
##Highino
#include <Led>
#include <Time>
int main() {
Led<13> led; // You could use 'BuiltinLed' instead of 'Led<13>' as well
// The pin is already set as Output (it is a LED!)
while (true) {
led.on(); // Simple on/off functions. You don't have to know what HIGH/LOW means to a LED
delay(1000_ms); // Notice a postfix here. You can also use '_s' for seconds or '_m' for minutes.
led.off();
delay(1_s); // This is the same as '1000_ms'
}
}Binary size: 670 bytes (43.2%).