Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Tip

This page presents the most basic programs that should first be tried out by every program when first getting their hands on a CrcDuino.

...

The following details the code lines that should be minimally used in every program that uses CrcLIbCrcLib.

Code Block
languagecpp
#include <CrcLib.h>

using namespace Crc;

void setup()
{
    CrcLib::Initialize();
}

void loop()
{
    CrcLib::Update();
}

//Lines starting with 2 slashes won't be compiled; they are comments.

/*This is a way 
to comment multiple lines of code */

...

This is how Arduino IDE loads the CrcLib when compiling the code, allowing the use use its functions. This will of course only work if the library as first been properly installed as detailed here.

...

Code Block
languagecpp
using namespace Crc;

...

The "setup" function is Arduino-specific. All the lines in the brackets right after it will be run executed only once, when the CrcDuino is powered up.

...

Code Block
void loop()
{
  //The code repeated as long as the board is powered up.
}

The "The “loop" function ” function is Arduino-specific and will be run repeatedly for . All the lines in the brackets right after it will be executed cyclically as long as your Arduino is runningthe CrcDuino is powered up.

...

Code Block
CrcLib::Update();

This call must be made in order to properly update the library on every loopperiodically update CrcLib data, including the remote controller state.

Using the Arduino IDE serial monitor

The Arduino serial monitor is a very useful tool that every programmer should be able to use when debugging their CrcDuino program. It allows the the CrcDuino to print messages to a computer screen. It can be used, for example, to confirm that a sensor state is read correctly by the CrcDuino. It most be opened in Arduino IDE to be used.

Note

Running a program with serial printing can dramatically slows its execution time, resulting in slower response time and greater power consumption.

Serial printing should therefore only be used for debugging and should be removed from the program executed during the Crc Robotics Competition playing game.

Code Block
languagecpp
#include <CrcLib.h>

using namespace Crc;

void setup()
{
    CrcLib::Initialize();
    Serial.begin(9600);  //Establishes a 9600 baud rate connection with the monitor.
}

void loop()
{
    CrcLib::Update();
    
    //Prints to the Serial monitor the Analog Input Port #1 value
    Serial.println(CrcLib::GetAnalogInput(CRC_ANA_1));
    
    //Prints the code execution time to the Serial monitor
    unsigned int deltaMicros = CrcLib::GetDeltaTimeMicros();
    Serial.println(deltaMicros);
}