Can someone please help me fix my code?
Basically, a user inputs values that determine how many beeps will play from a breadboard-compatible speaker, and right after the beeps are played, a motor (connected to the breadboard) is supposed to turn.
The beep-code is mine, and I got the motor code from the Arduino website. Anyway, SEPARATELY the codes work - the beeps play from the speaker, the motor turns fine. However, the codes don't work when I combine them (beeps play, but motor does not run after beeps are played), and I have no idea how to fix it. Any help is appreciated. Thanks so much.
int pin = 3;
#include <Stepper.h>
void setup() {
Serial.begin(9600);
}
void loop() {
int bpmeasure, measurespg, bpminute;
Serial.println("Enter number of beats per measure:");
while (Serial.available() == 0) {};
bpmeasure = Serial.parseInt();
Serial.println(bpmeasure);
Serial.println("Enter number of measures on page:");
while (Serial.available() == 0) {};
measurespg = Serial.parseInt();
Serial.println(measurespg);
Serial.println("Enter tempo:");
while (Serial.available() == 0) {};
bpminute = Serial.parseInt();
Serial.println(bpminute);
float tppg = (bpmeasure * measurespg * 60000.0) / bpminute;
// time it takes to play a page, in milliseconds
float tpbeat = tppg / (bpmeasure * measurespg);
// time between each individual note, in milliseconds
float t = 0.0;
for (float t = 0.0; t <= tppg ; t += tpbeat) {
tone (pin, 30, 50);
delay (tpbeat+50);
}
// speaker is supposed to beep every 'tpbeat' amount of milliseconds,
// until it reaches 'tppg' milliseconds and then speaker should stop beeping
const int stepsPerRevolution = 900;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int stepCount = 0;
// number of steps the motor has taken
if (stepCount = 0) {
// read the sensor value:
int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
// set the motor speed:
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution / 100);
}
}
}