Working With Source Code
Overview
We provide example source code for every Midnight Make product, and each kit (e.g., the µBee or the Pocket Bot) comes pre-flashed with its example code. This means you can use the kits out-of-the-box, but we assume you'll want to change the code or write your own, and that's what this guide is for!
As a starting point, you'll probably want to download the example source code for your kit. Pocket Bot code is available here, and µBee Drone Kit code is available here.
There are two main ways to write and compile your source code so it can be uploaded to your kit. If you're using Linux, you'll probably want to use avr-gcc directly. For Windows, we prefer Microchip Studio, although you can use avr-gcc instead if you wish. Use whichever section below that is appropriate for you.
Please note that this guide assumes basic familiarity with embedded C or C++, makefiles, and terminal usage. We do not provide programming tutorials, as there are endless excellent guides already available online.
Using Microchip Studio in Windows
First, download Microchip Studio here.
After downloading example source code, navigate to and open the .atsln file (the project file) for the kit whose source code you want to work with or modify.
Use the Build -> Build Solution main menu item to compile your code, as shown below. Note that we are in the Release build configuration, as also shown.

Assuming your compilation was successful, you should see a Build succeeded message in Microchip Studio's output, shown below.

A successful compilation will also result in new compiled code (.elf, .hex, and other files) in either your Debug or Release folder, depending on the build configuration. For example, a successful build of the Pocket Bot code will result in something like the following.

You don't need to interact with these files directly, as we provide scripts for uploading them onto your kit for you. See the guide for uploading code.
You can use the example code as a starting point for writing your own programs, or create your own Microchip Studio projects, which we discuss below.
Creating Your Own Microchip Studio Projects
There is a little bit of setup that goes into configuring these projects, so we'd recommend instead modifying the existing source code to suit your needs. However, if you'd like to start from scratch, this is certainly possible.
To do so, open Microchip Studio and select File -> New -> Project.

You should now select either GCC C Executable Project or GCC C++ Executable Project depending on whether you want to code in C or C++. Be sure of your selection since changing this after the fact is not easy. All Pocket Bot code uses the GCC C Executable Project setting, and the µBee Drone Kit uses the GCC C++ Executable Project setting.
Specify the name of the project and where it should live. Click OK.

Next, Microchip Studio wants to know which AVR device is used by your Midnight Make Kit. Both the µBee and the Pocket Bot use the ATmega328P, so scroll down and select that. Click OK.

Your project files will now be created, and you can begin writing your source code and/or drivers from scratch, or use the example code as a reference.
Using avr-gcc in Linux
Microchip Studio cannot be directly run in Linux, so we'll use avr-gcc.
Ubuntu users can install avr-gcc using the following:
sudo apt-get install gcc build-essential
sudo apt-get install gcc-avr binutils-avr avr-libc gdb-avr
The build workflow in Linux is simple. We provide makefiles for compiling our example programs. With avr-gcc correctly installed, you can simply run
make
to compile them. The provided makefiles can also be used as a reference for compiling your own source code.
After successful compilation, you can use the provided scripts to upload the compiled code onto your kit. See the guide for uploading code.
