Build a Wheel of Fortune with a 360-degree servo
FunduinoPublished on
Ein Zufallsgenerator mit 360-Grad-Servomotor und Taster
You need this
FS90R Micro Servo 360° - Continuous Rotation, 4.8-6 V, 60 RPM
8,55 € *Item no. F23108874About the product — FS90R Micro Servo 360° - Continuous Rotation, 4.8-6 V, 60 RPM
12x12x6 mm pushbutton - 2 pins, 2.54 mm pitch, normally open
0,49 € *Item no. F23106761About the product — 12x12x6 mm pushbutton - 2 pins, 2.54 mm pitch, normally open
All 2 parts together 9,04 € *Ready to ship immediately · Delivery time: 1-3 business days
* All prices include statutory VAT, plus shipping costs.
The 360-degree servo motor
Connect the pushbutton and motor
The program
Include the library and define variables
// eingebaute Bibliothek einbinden # include "Servo.h" // Name des Motors Servo Motor; // Minimum und Maximum der "Laufzeit" des Motors int Minimum = 300; int Maximum = 1500; // Pin des Tasters int Taster = 7; // Variable für die Drehrichtung int Drehrichtung;
The setup part
void setup()
{
// Motor an Pin 9
Motor.attach(9);
// Motor anhalten
Motor.write(90);
// Zufallsgenerator starten
randomSeed(analogRead(0));
// INPUT_PULLUP: Taster als Eingang definieren, Eingang auf HIGH setzen
pinMode(Taster, INPUT_PULLUP);
}The loop section
void loop()
{
// Check the button status
int TasterLesen = digitalRead(Taster);
// Button was pressed
if (TasterLesen == LOW)
{
// Determine the direction of rotation randomly
Drehrichtung = random(0, 2);
// Rotate the motor clockwise
if (Drehrichtung == 0) Motor.write(80);
// Rotate the motor counterclockwise
else Motor.write(100);
// Rotate for a random number of milliseconds
delay(random(Minimum, Maximum));
// Stop the motor
Motor.write(90);
}
}The template for the wheel of fortune
Rate the instructions