First Temperature read = 23C
Second Temperature Read = 23C
Move stepper motor and it works fine.
The temperature read after moving stepper = 27C and all reads after that.
Does anyone see a problem in this code that would cause this?
#include "CommandHandler.h"
#include <Stepper.h>
CommandHandler<> SerialCommandHandler;
// For your stepper motor
const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
int StepperRev = 0;
int inputPin = A0;
void setup()
{
// initialize serial communication with computer:
Serial.begin(9600);{
//Stepper
// set the speed at 15 rpm:
myStepper.setSpeed(10);
// Setup the serial commands too repond to
SerialCommandHandler.AddCommand(F("StepperRev"), Cmd_SetStepperRev);
SerialCommandHandler.AddCommand(F("TempReading"), Cmd_SetTempReading);
SerialCommandHandler.SetDefaultHandler(Cmd_Unknown); // Bad Serial Command
}
}
void loop()
{
// Check for serial commands and dispatch them.
SerialCommandHandler.Process();
}
void Cmd_SetStepperRev(CommandParameter &Parameters)
{
StepperRev = Parameters.NextParameterAsInteger(StepperRev);
for (int i = 0; i < StepperRev; i++)
{
Serial.println(StepperRev - i);
myStepper.step(stepsPerRevolution);
delay(500);
}
}
void Cmd_SetTempReading(CommandParameter &Parameters)
{
float TempReading = 0;
float Result = 0;
TempReading = analogRead(inputPin);
Result = map(TempReading * 100, 52600, 75800, -2000, 9000);
Serial.println (Result / 100);
}
void Cmd_Unknown()
{
Serial.println(F("I don't understand"));
}