Back

Sample Code for Friendship (Sample Two)

Here is a coding sample of how to use Friendship Coding to do something cool when your Jewelbot sees your red friends for the FIRST TIME (meaning the initial starting connection of being near a red friend). You can change this code to do different things for any and all color friends! Keep in mind that if you were to have code for two different friend colors AND you’re nearby both friend colors, then it will try to do both actions at the same time. This may cause animations to happen in a pattern or the color of the lights to blend.

Animation animation; void setup() { // put your setup code here, to run once } // Declare Jewelbots hardware components to use Buzzer buzz; Timer timer; Animation animation; // Declare booleans which control when you first see a friend of a particular color bool first_time_red = true; void loop() { // Red friend group: if ((see_red_friends()) && (first_time_red)) { buzz.short_buzz(); animation.rainbows(); buzz.short_buzz(); timer.pause(500); first_time_red = false; } else if ((!see_red_friends()) && (!first_time_red)) { first_time_red = true; } }

Note that a boolean is a “true or false” variable and that the && symbol represents “both must be true”.

So in the beginning, you declare a variable named “first_time_red” as true. And so, in the line “if((see_red_friends()) && (first_time_red))” you are saying that the Jewelbot must see red friends and the variable “first_time_red” must both be true. When that is the case, this code will do a buzz and rainbow animation, and at the end, set “first_time_red” to false.

Now, it can’t do a forever buzzing and rainbow loop until the Jewelbot no longer sees red friends. This is declared by the line “else if ((!see_red_friends()) && !(first_time_red))”. The exclamation in front symbolizes “false”. When the Jewelbot doesn’t see the red friends, then the function, “see_red_friends” is false. And because we set “first_time_red” as false in the “if” section, it is also false. These two false statements trigger the “else if” event to declare “first_time_red” as true again. Now, when your Jewelbot sees red friends again, it will do the buzzing and rainbows again.

BEFORE UPLOADING THE CODE, PUT YOUR JEWELBOT INTO UPLOAD MODE BY PLUGGING IN THE USB AND HOLDING THE MAGIC BUTTON DOWN FOR TWO SECONDS. Remember, two full seconds (1 mississippi...) Either the charging light will go out (if you did not update your firmware yet) or your device will flash purple and then fade to indicate that coding mode is activated (if you updated your firmware).

CLICK ON THE UPLOAD BUTTON FROM THE ARDUINO IDE TO TRANSFER THE CODE TO YOUR JEWELBOT.

ONCE THE CODE IS UPLOADED ONTO YOUR JEWELBOT, UNPLUG IT TO SEE THE RESULTS!! The act of your Jewelbot running your code is it being in Coding Mode! (Isn't that cool?!)

TEST OUT MORE CODE COMBINATIONS BY DOING THIS WITH DIFFERENT COLOR FRIEND GROUPS!

SHARE WHAT YOU CODE FOR YOUR JEWELBOT HERE ON THE FORUMS!

Troubleshooting

I'm getting an error I didn't have before?

Try updating your Arduino Library board to make sure you have the most recent coding functions! Go to Tools > Boards > Boards Manager. Search "j" to get the Jewelbots Friendship Coding board. Then hit update!

I'm getting an error that says "failed to execute _main script"

This is an error Mac users get (and we're not sure why yet!), but just ignore it. It doesn't affect how your Jewelbot gets programmed! As long as it says "Device Programmed" or “Upload Complete” at the end, then just unplug your Jewelbot to see the results!

There's an error that says "Possible causes: -boot loader..." etc

Make sure you have the correct Board and Port selected. If you do, then make sure to put your Jewelbot in Upload Mode by pressing it for 2 seconds while plugged in when you hit the upload button.

Getting an error that says error: 'LED' was not declared in this scope

Some suggestions to solve this would be:

If none of these solutions seem to help, then email us at hi@jewelbots.com