#include <Servo.h>
// Pin Definitions
const int buttonPin = 2; // Button to start/stop the Ferris wheel
const int ledPins[] = {3, 4, 5, 6, 7}; // LEDs representing cabins
const int ledCount = 5; // Number of LEDs
Servo ferrisServo; // Servo motor for wheel rotation
const int servoPin = 9;
// Variables
bool isRunning = false; // Ferris wheel running state
int ledIndex = 0; // Current LED index
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // Button setup with pull-up
ferrisServo.attach(servoPin); // Attach servo to pin
// Initialize LEDs
for (int i = 0; i < ledCount; i++) {
pinMode(ledPins[i], OUTPUT);
digitalWrite(ledPins[i], LOW);
}
// Set servo to starting position
ferrisServo.write(0);
}
void loop() {
// Check button press to toggle the running state
if (digitalRead(buttonPin) == LOW) {
delay(200); // Debounce delay
isRunning = !isRunning;
}
if (isRunning) {
rotateFerrisWheel();
}
}
// Function to simulate Ferris wheel rotation
void rotateFerrisWheel() {
// Turn on the current LED and turn off the previous one
for (int i = 0; i < ledCount; i++) {
digitalWrite(ledPins[i], (i == ledIndex) ? HIGH : LOW);
}
// Move servo slightly to simulate rotation
ferrisServo.write(ledIndex * (180 / ledCount));
// Move to the next LED
ledIndex = (ledIndex + 1) % ledCount;
delay(1000); // Pause for rotation
}