Adapt your current Arduino projects and sketches to biicode. Next steps depend on whether your project contains one single .ino
file, or multiple .ino
files. Just follow the guide that suits best your current project:
This is the simplest case. Adaptation is almost immediate:
General rules
Change .ino
file extensions to .cpp
. For example, sweep.ino
file would be sweep.cpp
.
Include the Arduino.h
library in the very beginning of your code:
#include "Arduino.h"
Declare all function prototypes at the beginning of your code. For example: void servo_loop();
.
If you’re using 3rd party (external) libraries, search for them in biicode and rewrite the library includes to the ones available on biicode. Usually, all included files in biicode projects follow this pattern: <username>/<blockname>/<path_to_file>
.
For example, if you are using Tiny GPS Library ,
tinygps.h
, you should update the include directive like this:#include "mikalhart/tinygps/tinygps.h"
Full .ino
file adaptation Sample:
Original sweep.ino file
#include <Servo.h>
void setup(){
}
void loop(){
servo_loop(9);
}
void servo_loop(int pin) {
Servo myservo;
myservo.attach(pin);
for (int pos = 0; pos <= 180; pos += 1){
myservo.write(pos);
delay(15);
}
}
Adapted sweep.cpp file
#include "Arduino.h"
#include <Servo.h>
void servo_loop();
void setup(){
}
void loop(){
servo_loop(9);
}
void servo_loop(int pin){
Servo myservo;
myservo.attach(pin);
for (int pos = 0; pos <= 180; pos += 1){
myservo.write(pos);
delay(15);
}
}
General rules
Change .ino
main file extension to .cpp
. Also, change the extension of the other .ino
files to .h
.
For example, if your project has the following layout, being
sweep.ino
your main file:+-- sweep | +-- sweep.ino | +-- servo_functions.inoRename
sweep.ino
tosweep.cpp
, andservo_functions.ino
toservo_functions.h
. Put them into yourproject/blocks/username/biicode_block_name
directory like this:+-- <biicode_block_name> | +-- sweep.cpp | +-- servo_functions.h
Include the Arduino.h
library in the very beginning of your code:
#include "Arduino.h"
If you’re using 3rd party (external) libraries, search for them in biicode and rewrite the library includes to the ones available on biicode. Usually, all included files in biicode projects follow this pattern: <username>/<blockname>/<path_to_file>
.
For example, if you are using Tiny GPS Library ,
tinygps.h
, you should update the include directive like this:#include "mikalhart/tinygps/tinygps.h"
Declare all function prototypes at the beginning of your code. For example void servo_loop();
.
Find below a full multiple .ino
files adaptation sample. Easy adaptation is the one described before and advanced adaptation is the one biicode recommends for complex projects o nice practice:
Original sweep Arduino project
sweep.ino
void setup(){
}
void loop(){
servo_loop(9);
}
servo_functions.ino
#include <Servo.h>
void servo_loop(int pin){
Servo myservo;
myservo.attach(pin);
for (int pos = 0; pos <= 180; pos += 1){
myservo.write(pos);
delay(15);
}
}
Easy adaptation
sweep.cpp
#include "servo_functions.h"
void setup(){
}
void loop(){
servo_loop(9);
}
servo_functions.h
#include "Arduino.h"
#include <Servo.h>
void servo_loop(int pin){
Servo myservo;
myservo.attach(pin);
for (int pos = 0; pos <= 180; pos += 1){
myservo.write(pos);
delay(15);
}
}
Advanced adaptation
This is an alternative way to adapt your code to biicode. It is recommended as a best practice that splits your code into declarations, or interface, and implementations. This separation between interface (contained in header files, with .h
extension) and implementation (contained in .cpp
files) provides many benefits:
sweep.cpp
#include "servo_functions.h"
void setup(){
}
void loop(){
servo_loop(9);
}
servo_functions.h
#include "Arduino.h"
void servo_loop(int pin);
servo_functions.cpp
#include "servo_functions.h"
#include <Servo.h>
void servo_loop(int pin){
Servo myservo;
myservo.attach(pin);
for (int pos = 0; pos <= 180; pos += 1){
myservo.write(pos);
delay(15);
}
}