Note |
---|
Cette page présente de l’information essentielle à propos de CrcLib. |
Rules to follow
Make sure to respect the following rules to ensure the proper execution of a code containing CrcLib functions:
Do not use the Arduino native delay() function.
Do not use sensors outputting only a variable-width pulse, also called TTL pulse, like the Parallax PING and its knockoffs like the HC-SR04.
Use while(), do…while() and for() functions with caution. If the program execution is intentionally kept for a long time inside a loop, make sure to include a
CrcLib::Update()
call in it so that data used by CrcLib is correctly refreshed at an appropriate rate.
Why follow these rules?
The delay() function stops the code execution for a given time, and most of the time it’s a bad thing. An Arduino code that runs CrcLib should, like the vast majority of micro-controller code, always be looping through a set of instructions at a certain rate.
...
Code Block | ||
---|---|---|
| ||
#include <CrcLib.h>
#define BUTTON_LAUNCH_PROGRAM CRC_DIG_1 //This renames CRC_DIG_1 to BUTTON_LAUNCH_PROGRAM
using namespace Crc;
void setup() {
CrcLib::Initialize();
CrcLib::SetDigitalPinMode(CRC_DIG_1,INPUT);
Serial.begin(2000000);
}
void loop() {
CrcLib::Update(); //Out of the loop call
Serial.println("Out of the loop");
Serial.println(CrcLib::GetDigitalInput(BUTTON_LAUNCH_PROGRAM));
if (CrcLib::GetDigitalInput(BUTTON_LAUNCH_PROGRAM)==LOW) //The button is pressed
{
while(1==1)
{
Serial.println("Program executes this loop until board reset or power loss");
CrcLib::Update(); //In loop call
//Insert the robot code here.
}
}
} |
...