// Define stepper motor connections and steps per revolution: #define dirPin 1 #define stepPin 2 const int numberOfSteps = 200; const int numberOfStepsIncrease = 32; const int stepsPerRevolution = numberOfSteps * numberOfStepsIncrease; int rotationTimePerSecond = 7; // 1 rotate in 4 second (1 ) int micPin = 28; // Analog pin connected to microphone int clapDetected = 0; // Flag to indicate clap detection void setup() { // Declare pins as output: pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT); Serial.begin(9600); } void loop() { // Set the spinning direction clockwise: digitalWrite(dirPin, HIGH); if (Serial.available() > 0) { // Check if data is available to read int mentionedSpeed = Serial.parseInt(); // Read incoming byte Serial.print("Received: "); Serial.println(mentionedSpeed); // Print received character rotationTimePerSecond = mentionedSpeed; } if (rotationTimePerSecond > 0) { z for (int i = 0; i < stepsPerRevolution; i++) { // These four lines result in 1 step: digitalWrite(stepPin, HIGH); delayMicroseconds(rotationTimePerSecond * 500000/stepsPerRevolution); digitalWrite(stepPin, LOW); delayMicroseconds(rotationTimePerSecond * 500000/stepsPerRevolution); } } }