Here are some helpful Utilities for coding your Jewelbots

Back

These Utilities will help you make your code more powerful. The Jewelbots Utilities are here to help you! Check them out below.

.get_random_int(x,y)

This function returns a random number in between two integers.

rand_value = get_random_int(1,4); //rand_value will equal a random integer between 1 and 4

The Timer Class

The Timer class constructs an object that allows you to create a delay between other Jewelbot functions or keep track of time since the program started running.

COMPONENT INTIALIZATION

Timer timer; //naming the variable type and then the name of variable.

The different functions are called the "API", because they are the way you interact with the device. APIs are ways you can work with different interfaces, sometimes in a computer and sometimes online.

API

.pause(uint32_t milliseconds)

This function pauses your Jewelbot.

Timer timer; timer.pause(1000); //this pauses your Jewelbot for 1 second.

.runtime_ms()

This function returns the number of milliseconds since the program finished starting up the hardware. The return value is of type uint32_t.

Timer timer; uint32_t how_long = timer.runtime_ms();

USB Serial Output

There are two functions available which allow for outputting messages and variable values from the Jewelbot. The primary objective of these messages is typically for debugging purposes, to learn where and how your program is running. The messages output from the Jewelbot can be viewed on the Serial Monitor. The Serial Monitor is located in the Tools menu of the Arduino IDE. Before accessing the Serial Monitor, the Jewelbot must be plugged in and the proper USB port selected under the Tools -> Port: menu. Once the Jewelbots Friendship Board is selected, there is an example sketch of this functionality under the File -> Examples -> Jewelbots_Examples called USB_output.ino. Before getting to outputting messages, a function must be set up on the Jewelbot to enable the messaging.

Setup for Serial Output

The set_run_loop_charging() function sets an internal switch in the code so the Jewelbot will run the loop() function while it is plugged in to USB power. Typically the Jewelbot does not run the loop() function while charging so that the charge status can be displayed. In this case, since the USB must be plugged in for the desired output to be sent to the computer, this function tells the Jewelbot to run loop() while plugged in to power. To utilize set_run_loop_charging(), place the function inside the setup() section of the sketch:

void setup() { // put your setup code here, to run once: // Function to tell the Jewelbot to run the loop() function // while plugged into USB power set_run_loop_charging(); }

USB output API

JWB_SERIAL(string to output)

This function prints a string message to the Serial Monitor.

JWB_SERIAL("Debugging message.\n");

JWB_SERIAL_PRINTF(string with formatting, variable)

This function prints a string message and variable value to the Serial Monitor.

JWB_SERIAL_PRINTF("x = %u\n", x);

Both functions follow the standard C formatting rules. The "\n" character in the above examples is for a new line, so each message will start on its own line.