# Get Started

Sphero created Oval as a subset of the C-language to communicate with our robots, and we now offer it to anyone in the world to use it as a fun tool to learn computer programming. This site is a guide to programming Sphero robots using Oval in the Lightning Lab App. If you're learning to program for the first time the best place to start is our Text Series of Activities. If you are a developer interested in building an app for Sphero use our SDK documentation.

### How is Oval used?

Oval is used to control nearly everything on Sphero, Ollie and BB-8 with a standard set of commands. A few of the coolest features in our apps that Oval brings to life are:

Lightning Lab - Powers the draw, blocks and text canvases to write custom programs.

BB-8 - Powers Watch With Me animations during Star Wars: The Force Awakens™.

Ollie - Powers the trick pad to make Ollie a trick machine.

### Hello World!

Your first program will set the LED color to blue and roll the robot straight forward for 1s. On your device with the Lightning Lab app, open a new text program, click the ? button in the upper right, and use the Copy button below to copy and paste these code samples. Tap the Start button and see what happens:

void startProgram() // don't forget to aim your bot
{
setRgbLed(0, 0, 255);
controlSystemTargetSpeed = 60;
delay(1);
controlSystemTargetSpeed = 0;
}

### Hello Square!

Let's transform your first program into a Square with more logic. Now run this program:

int _loopCount_1 = 0; // 1 is the unique value for this loop

void startProgram()
{
controlSystemTargetYaw = 270;
while (_loopCount_1 < 4) // 4 is the # of loops
{
_loopCount_1 = _loopCount_1 + 1;
playSound(2, 6); // engine drive by sound
delay(0.05);
setRgbLed(0, 0, 255);
controlSystemTargetYaw = controlSystemTargetYaw + 90; //add 90°
delay(1);
controlSystemTargetSpeed = 60;
delay(1);
controlSystemTargetSpeed = 0;
}
}

### Oval Virtual Machine

Most computer languages run on a computer, mobile device, or server, but Oval runs on Sphero robots on a Virtual Machine that we call the Oval Virtual Machine (OVM). The OVM emulates the concept of a "computer" on Sphero robots enabling us to execute complex code. When you run a program from Lightning Lab, the Oval code compiles into binary (1's & 0's), and then travels wirelessly over Bluetooth to run via the OVM on the robot.

Oval is a streaming language that you can interact with in real-time. For example, the trick pad in the Ollie App has lots of pre-defined trick functions written in Oval. Tricks are "called" when you drag the trick pad a certain way, like Steam Roll, which interrupts driving commands to perform the trick. Tricks and can be continuously called.

# Syntax

Syntax is the rule set for how programs are constructed.

### Character Case

Oval identifiers are tough to describe with one word, so most are 2-4 words known as "compound identifiers." Programming langauges generally don't allow spaces in identifers, so character case is the method by which you join compound identifiers to deliminate words. While there are hundreds of programming languages in the world, nearly all of them use one of these four joining methods: thisIsCamelCase, ThisIsPascalCase, this-is-spinal-Case, and this_is_snake_case. Oval is case sensitive and uses camelCase, such as controlSystemTargetSpeed to set the speed.

### Punctuation

Code needs to be structured so it can be interpreted by the robot, just like the way humans have agreed on punctation standards in writing. If authors did not write with consistent punctation, readers would find it difficult to learn new rules in every book they read. Pay very close attention to the use of these characters or your robot will not be able to "read" your program:

void startProgram() starts a program

{ and } contain all program code, except for global functions and variables

// indicates a comment but does not affect the program logic

; ends a statement

( ) contains a value

, separates values

_____ a tab space starts the first statement in a program, and subsequent conditions must indent further

### Highlighting

Notice in your Hello World! program that the words and characters are different colors. Syntax highlighting is the scheme to determine which commands display in which color. This scheme is different than the simplified one used in the block canvas.

native oval identifers
data types
syntax characters, comparators, operators, custom identifiers
values
controls
comments
errors

### Errors

Errors tell you when the robot can't interpret your syntax. In the below example, notice a ; is missing after the speed value. In this case the robot is missing the context for the end of the statement and the red error message will display below the error line:

void startProgram()
{
controlSystemTargetSpeed = 188
//!Syntax error!
setRgbLed(13, 255, 33);
delay(2);
}

### Data types

There are different types of data in programming that describe how much space a number occupies in storage and how it's interpreted. The memory on Sphero robots is quite small compared to a computer, so Oval is designed to use tiny amounts of space and only supports subsets of the data types in the C-Language:

Supported - Basic Types
int are whole numbers without a decimal, aka integers, such as 2
float are numbers with a decimal or remainder, such as 2.1

Unsupported - Enumerated Void Types
pointer
array
structure
union
function