user30670: 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);
    }
  }
}


user4143: The first step with combining any programs together is to forget about combining programs together. Instead you need to do something completely different.
Analyse the existing programs individually. Work out and learn exactly how they work and how they do what they do.
Then think about your program. What do you actually want it to do, and how does that relate to the things the other programs did.
Then, finally, using what you learned from analysing the other programs, you write your own new program that does what you want it to do. 
Yes, there may be a certain amount of copy-and-paste from the old programs to the new, but until you have taken the time to learn how the old programs work you won't have a clue which parts of them you may want to copy-and-paste, and which you may want to use as inspiration for writing new portions of code.

30670: <p>Can someone please help me fix my code? </p>

<p>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. </p>

<p>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. </p>

<pre><code>int pin = 3;
#include &lt;Stepper.h&gt;

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 &lt;= 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 &gt; 0) {
      myStepper.setSpeed(motorSpeed);
      // step 1/100 of a revolution:
      myStepper.step(stepsPerRevolution / 100);
    }
  }
}
</code></pre>
 4143: <p>The first step with combining any programs together is to forget about combining programs together. Instead you need to do something completely different.</p>

<p>Analyse the existing programs individually. Work out and learn exactly how they work and how they do what they do.</p>

<p>Then think about your program. What do you actually want it to do, and how does that relate to the things the other programs did.</p>

<p>Then, finally, using what you learned from analysing the other programs, you write your own new program that does what you want it to do. </p>

<p>Yes, there may be a certain amount of copy-and-paste from the old programs to the new, but until you have taken the time to learn how the old programs work you won't have a clue which parts of them you may want to copy-and-paste, and which you may want to use as inspiration for writing new portions of code.</p>
