> ## Documentation Index
> Fetch the complete documentation index at: https://stem-docs.intellectualpoint.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Programming a drone

> Meet block coding and echo.pitsco.com - how you'll turn your drone from hand-flown to self-flying.

## From pilot to programmer

For two days you've flown your drone by hand. Today it levels up: instead of you holding the sticks, **your code** flies the drone. You'll give it a list of instructions - take off, fly forward, spin, land - and it carries them out on its own.

<Frame caption="You snap together blocks, and the drone flies the program">
  <img src="https://mintcdn.com/intellectualpoint/eW7U9shBQKKM3XX9/images/drones/block-coding.png?fit=max&auto=format&n=eW7U9shBQKKM3XX9&q=85&s=0534ec829a1c9cb1b5ec9c1aaa79ced5" alt="Block coding concept: a stack of drone command blocks" width="1536" height="1024" data-path="images/drones/block-coding.png" />
</Frame>

## What is a program?

A **program** is just a list of instructions a computer follows in order. You already think this way - a recipe or a set of directions is a program for a person. A drone program is a set of steps for the drone:

```text theme={null}
1. take off
2. hover for 1 second
3. fly forward
4. land
```

The computer does each step exactly, in order, every time - which is why code can fly a path far more precisely than your hands can.

<Frame caption="A program is a recipe: the drone follows your steps in order, exactly, every time">
  <img src="https://mintcdn.com/intellectualpoint/eW7U9shBQKKM3XX9/images/drones/program-as-recipe.png?fit=max&auto=format&n=eW7U9shBQKKM3XX9&q=85&s=f89765a719d5914d20a93530259c6492" alt="A program compared to a recipe, with numbered steps the drone follows in order" width="1536" height="1024" data-path="images/drones/program-as-recipe.png" />
</Frame>

<Tip>
  **Instructor prompt:** Ask a student to give you step-by-step directions to make a peanut butter sandwich - then follow them *too literally* (e.g. "put peanut butter on bread" → smear the jar on the loaf). Kids learn instantly that computers do *exactly* what you say, not what you mean. This is the single most important idea of the whole day.
</Tip>

## The three things every program does

Almost every program - from a drone flight to a video game - is built from just three simple ideas. You'll use all three this week:

<CardGroup cols={3}>
  <Card title="Sequence" icon="list-ordered">
    Steps run **in order**, top to bottom. Take off *before* you fly forward.
  </Card>

  <Card title="Loops" icon="repeat">
    **Repeat** steps without copying them. Fly a square with one small loop instead of eight blocks.
  </Card>

  <Card title="Decisions" icon="git-branch">
    **If-then** choices let a program react - "if battery is low, land." (You'll dig into these on Day 5.)
  </Card>
</CardGroup>

## Block coding

You'll write programs by **snapping together blocks** - no typing, no syntax errors. Each block is one instruction (like "take off" or "fly forward"). You drag them into order and press play. It's the same idea as Scratch, and it's how most people start coding.

<Frame caption="Blocks on the left, the real JavaScript they stand for on the right - same program, two views">
  <img src="https://mintcdn.com/intellectualpoint/eW7U9shBQKKM3XX9/images/drones/blocks-vs-code.png?fit=max&auto=format&n=eW7U9shBQKKM3XX9&q=85&s=5b23221e4875ed3d24f4e00cdae5a8c7" alt="Comparison of block coding and the equivalent JavaScript text code" width="1536" height="1024" data-path="images/drones/blocks-vs-code.png" />
</Frame>

Blocks aren't "fake" coding - each block stands for a real line of code. Later today you'll flip a switch and watch your blocks turn into professional JavaScript, the same language that runs most of the web.

## Meet echo.pitsco.com

This week's coding tool is **echo.pitsco.com** - a free website that talks to your drone. There's nothing to install and no account needed.

<Frame caption="The echo.pitsco.com workspace once your drone is connected">
  <img src="https://mintcdn.com/intellectualpoint/eW7U9shBQKKM3XX9/images/drones/echo-workspace.png?fit=max&auto=format&n=eW7U9shBQKKM3XX9&q=85&s=70dbc770941e96b13691aa4054c324ac" alt="The echo.pitsco.com interface showing the toolbar and block categories" width="1024" height="623" data-path="images/drones/echo-workspace.png" />
</Frame>

Here's what you'll see:

<CardGroup cols={2}>
  <Card title="Block categories (left)" icon="blocks">
    **Flight, Control, Loops, Variables, and Functions** - each is a drawer of blocks you drag into your program.
  </Card>

  <Card title="Toolbar (top)" icon="wrench">
    **FILE, EDIT, CONNECT, START PROGRAM, and LAND NOW** control your drone and your work.
  </Card>

  <Card title="Your save code (top center)" icon="hash">
    A short code (like `FZD6O4`) that saves your work so you can continue later with **I have a code**.
  </Card>

  <Card title="Blocks / Javascript (bottom right)" icon="braces">
    Switch between drag-and-drop blocks and real JavaScript with the **Views** toggle.
  </Card>
</CardGroup>

<Info>
  echo.pitsco.com connects to your drone over **Bluetooth**, straight from your web browser. Open the site in **Google Chrome or Microsoft Edge** (Bluetooth coding isn't supported in Safari).
</Info>

## Bluetooth vs the controller

Your drone can listen to the controller **or** to your code, but not both at once:

* **Controller** (Days 1-2): you fly by hand with the joysticks.
* **Bluetooth code** (today): the website sends your program to the drone.

<Warning>
  When you connect the drone to echo.pitsco.com, the handheld controller won't work - the drone is now listening to your code. That's expected.
</Warning>

## Why code a drone at all?

<CardGroup cols={2}>
  <Card title="Precision" icon="crosshair">
    Code repeats the *exact* same flight every time. Your hands never will.
  </Card>

  <Card title="Repeatability" icon="repeat">
    Run the same mission a hundred times - for inspections, mapping, or delivery.
  </Card>

  <Card title="Autonomy" icon="robot">
    A coded drone flies itself. Real drones survey fields and film movies with no pilot touching the sticks.
  </Card>

  <Card title="Superpowers" icon="wand-sparkles">
    Loops, timers, and decisions let one program do things no human pilot could do by hand.
  </Card>
</CardGroup>

## Talk about it

<Info>
  **Discussion prompts to keep the room buzzing:**

  * What's a "program" you follow every morning before school? (A morning routine is a sequence!)
  * If a self-driving car ran its instructions *too literally*, what could go wrong?
  * Would you rather fly the drone by hand or write code that flies it perfectly every time? Why?
</Info>

<Check>
  You can explain what a program is, name the three building blocks of every program (sequence, loops, decisions), name the five block categories in echo.pitsco.com, and describe how it connects to your drone.
</Check>
