Learn / Arduino / Cyclone
Cyclone code walkthrough
A simple Arduino program inspired by the Cyclone arcade game. The goal is to use one small project to explain what Arduino code is actually doing.

The arcade game is called Cyclone. Lights travel around the ring, and you press a button to stop the light on the jackpot position.
What this lesson is trying to do
Cyclone is a really good Arduino teaching example because it lets you explain variables, arrays, functions, loops, timing, button input, and simple game logic without the program becoming too complicated.
- Several LEDs act like the moving light.
- A button stops the light.
- One LED position is treated as the jackpot.
- Serial Monitor prints what happened.
First, the basic things you wanted explained
What is Arduino.h?
Arduino.h is basically the main Arduino core header.
It gives your program access to the standard Arduino stuff like:
pinMode()digitalWrite()digitalRead()delay()millis()HIGHLOWINPUT_PULLUP- built-in data types and helpers used by Arduino sketches
In normal .ino sketches, the Arduino IDE usually handles this for you behind the scenes, so you often don’t need to manually write #include <Arduino.h>.
But if you are working in PlatformIO or more explicit .cpp-style files, you usually include it yourself.
So yes: it is essentially the core Arduino library/header that gives you the Arduino environment.
What does setup() do?
setup() runs once when the board powers on or resets.
This is where you usually do things like:
- set pin modes
- start Serial
- initialize sensors or displays
Example:
void setup() {
pinMode(13, OUTPUT);
}That means: “when the Arduino starts, make pin 13 an output.”
What does loop() do?
loop() runs over and over forever after setup() finishes.
That’s the heartbeat of most Arduino programs.
Example:
void loop() {
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}That code keeps blinking forever because loop() keeps repeating.
Why void?
void means the function does not return a value.
So:
void setup()means:
- this is a function called
setup - it does not give anything back
Same with loop().
If a function does return something, you use another type:
int addNumbers(int a, int b) {
return a + b;
}That returns an int.
So quick version:
void= returns nothingint= returns a whole numberbool= returns true/falsefloat= returns decimal number
Wiring diagram

- LED pins: D2 through D7
- Button pin: D8
- Each LED should have its own 220-330 ohm series resistor: digital pin to resistor to LED anode; LED cathode to GND.
- The button uses
INPUT_PULLUP, so one side goes to D8 and the other goes to GND
Use the D2-D7 and D8 pin names above when wiring. The supplied illustration is conceptual: its colored pin labels do not consistently match the board header positions. Disconnect USB power before changing connections.
Arduino example: Cyclone-style LED game
Here’s a basic Cyclone-style program with lots of comments, but still readable. It uses several LEDs in a row, one button, and one jackpot position.
Use an Arduino Uno R3 (5 V) with VS Code + PlatformIO, board uno, platform atmelavr, framework arduino. Save this complete program as src/main.cpp and the shared configuration below as platformio.ini in the project root. Build, then Upload, and open PlatformIO Monitor at 9600 baud. Reset the board to start another round. This simple example detects a button edge without adding a debounce filter.
#include <Arduino.h>
// In this PlatformIO C++ program, include Arduino.h explicitly.
// It is the header that gives you the normal
// Arduino environment: pinMode(), digitalWrite(), digitalRead(), millis(), HIGH,
// LOW, INPUT_PULLUP, and many other familiar functions and constants.
// These are the pins used for the row of LEDs.
// We store them in an array so we can treat them as a group.
const int ledPins[] = {2, 3, 4, 5, 6, 7};
// This calculates how many LEDs are in the array.
const int ledCount = sizeof(ledPins) / sizeof(ledPins[0]);
// The button pin.
// We will use INPUT_PULLUP, so the logic will be inverted:
// HIGH = not pressed, LOW = pressed.
const int buttonPin = 8;
// The player is trying to stop the moving light on this position.
const int jackpotIndex = 3;
// currentIndex tracks which LED is currently lit.
int currentIndex = 0;
// moving tells us whether the light is still sweeping.
bool moving = true;
// These variables help us move the light at regular time intervals.
unsigned long lastStepTime = 0;
const unsigned long stepInterval = 120;
// We remember the old button state so we can detect the moment the button is pressed.
int lastButtonState = HIGH;
// A void function does work but does not return a value.
// This one turns every LED off.
void clearLeds() {
for (int i = 0; i < ledCount; i++) {
digitalWrite(ledPins[i], LOW);
}
}
// Another void function.
// It lights only the current LED.
void showCurrentLed() {
clearLeds();
digitalWrite(ledPins[currentIndex], HIGH);
}
// This function returns a bool, which means true or false.
// It answers the question: are we on the jackpot position?
bool isJackpot() {
return currentIndex == jackpotIndex;
}
// setup() runs once when the board powers on or resets.
// This is where we configure pins and start Serial.
void setup() {
for (int i = 0; i < ledCount; i++) {
pinMode(ledPins[i], OUTPUT);
}
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
showCurrentLed();
Serial.println("Cyclone practice game started!");
Serial.println("Press the button to stop the moving light.");
}
// loop() runs over and over forever after setup() finishes.
// This is where the main game behavior lives.
void loop() {
int buttonState = digitalRead(buttonPin);
if (moving) {
// millis() returns the number of milliseconds since the board started.
// This lets us do timing without freezing the whole program.
unsigned long now = millis();
if (now - lastStepTime >= stepInterval) {
lastStepTime = now;
currentIndex++;
// If the light goes past the last LED, wrap back to the first one.
if (currentIndex >= ledCount) {
currentIndex = 0;
}
showCurrentLed();
}
}
// Detect the instant the button changes from not pressed to pressed.
if (lastButtonState == HIGH && buttonState == LOW) {
moving = false;
Serial.print("Stopped on LED index: ");
Serial.println(currentIndex);
if (isJackpot()) {
Serial.println("JACKPOT!");
} else {
Serial.println("Missed it. Try again.");
}
}
lastButtonState = buttonState;
}
PlatformIO configuration: platformio.ini
[env:uno]
platform = atmelavr
board = uno
framework = arduino
monitor_speed = 9600
Why this is a good teaching program
| Code | Why it matters |
|---|---|
const int ledPins[] = {2, 3, 4, 5, 6, 7}; | Creates an array so multiple LED pins can be handled as one group. |
for (int i = 0; i < ledCount; i++) | A loop that repeats code for each LED. |
pinMode(buttonPin, INPUT_PULLUP); | Turns on the Arduino's internal pull-up resistor so the button wiring stays simple. |
unsigned long now = millis(); | Reads elapsed time without freezing the whole program with delay(). |
bool isJackpot() | A function that returns true or false. |
if (lastButtonState == HIGH && buttonState == LOW) | Detects the moment the button is pressed. |
- Arrays: one list of LED pins instead of six separate variables.
- Functions: breaks the program into smaller reusable pieces like
clearLeds()andshowCurrentLed(). - Conditions: the game decides whether to keep moving, wrap back to the first LED, or print JACKPOT.
- Timing:
millis()introduces better habits than usingdelay()for everything. - Button logic:
INPUT_PULLUPteaches the inverted HIGH/LOW logic beginners often find confusing.
Where to go next
- Return to the main Arduino reference page.
- Look up any unfamiliar syntax in the tables on the Arduino page.
- Try changing
stepInterval,jackpotIndex, or the number of LEDs and see how the behavior changes.