Having some more trouble with my code today. I am trying to use the If, Elseif, Elseif, Elseif, Else statement in my void loop(); function to call another function gotofirstsensor(), etc. However when I call it the stepper motor does not active. When I call gohome(); in void startup() it works fine, and when I control the motor directly from the loop it works fine, but when I call the gotofirstsensor() function if one part of the if, elseif…else statement It goes to it (The println goes off) then it just goes right back into the loop with out doing any of the myStepper.step(STEPS) code.
Code is below, and thanks once again for your help.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Stepper.h>
#include <Arduino.h>
// Map our pins to constants to make things easier to keep track of
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;
float temperaturearray[] = {0, 0, 0, 0, 0};
float sensorcount = 5;
float largest = 0;
//steps by 28, 56, 84, 112
const int STEPS = 200; //steps in a 360 degree revoltion
Stepper myStepper(STEPS, dirA, dirB); //initalize stepper class
#define ONE_WIRE_BUS 2 /*-(Connect to Pin 2 )-*/
OneWire ourWire(ONE_WIRE_BUS);
DallasTemperature sensors(&ourWire);
DeviceAddress Probe01 = { 0x28, 0x86, 0x66, 0x67, 0x04, 0x00, 0x00, 0x43 };
DeviceAddress Probe02 = { 0x28, 0x49, 0x36, 0x67, 0x04, 0x00, 0x00, 0x6D };
DeviceAddress Probe03 = { 0x28, 0xC7, 0x6B, 0x67, 0x04, 0x00, 0x00, 0xED };
DeviceAddress Probe04 = { 0x28, 0x56, 0x40, 0x67, 0x04, 0x00, 0x00, 0xE3 };
DeviceAddress Probe05 = { 0x28, 0xCB, 0x3D, 0x68, 0x04, 0x00, 0x00, 0x03 };
void setup() /****** SETUP: RUNS ONCE ******/
{
// start serial port to show results
Serial.begin(9600);
Serial.print("Initializing Temperature Control Library Version ");
Serial.println(DALLASTEMPLIBVERSION);
// Initialize the Temperature measurement library
sensors.begin();
// set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
sensors.setResolution(Probe01, 12);
sensors.setResolution(Probe02, 12);
sensors.setResolution(Probe03, 12);
sensors.setResolution(Probe04, 12);
sensors.setResolution(Probe05, 12);
// Set the RPM of the motor
myStepper.setSpeed(30);
// Turn on pulse width modulation
pinMode(pwmA, OUTPUT);
digitalWrite(pwmA, HIGH);
pinMode(pwmB, OUTPUT);
digitalWrite(pwmB, HIGH);
// Turn off the brakes
pinMode(brakeA, OUTPUT);
digitalWrite(brakeA, LOW);
pinMode(brakeB, OUTPUT);
digitalWrite(brakeB, LOW);
gohome();
Serial.println("words complete");
Serial.begin(9600);
}//--(end setup )---
void loop(){
Serial.println("entered loop");
fillarray(temperaturearray);
Serial.print("S1: ");
Serial.println(temperaturearray[0]);
Serial.print("S2: ");
Serial.println(temperaturearray[1]);
Serial.print("S3: ");
Serial.println(temperaturearray[2]);
Serial.print("S4: ");
Serial.println(temperaturearray[3]);
Serial.print("S5: ");
Serial.println(temperaturearray[4]);
highestTemperature(temperaturearray);
Serial.print("largest length: ");
Serial.println(largest);
if (largest == temperaturearray[0])
{
Serial.println("Went to 1st");
gotofirstsensor;
}
else if (largest == temperaturearray[1])
{
Serial.println("Went to 2nd");
gotosecondsensor;
}
else if (largest == temperaturearray[2])
{
Serial.println("Went to 3rd");
gotothirdsensor;
}
else if (largest == temperaturearray[3])
{
Serial.println("Went to 4th");
gotofourthsensor;
}
else
{
Serial.println("Went to 5th");
gotofifthsensor;
}
Serial.println("why am I here?");
delay(5000);
}
float highestTemperature(float temperaturearray[])
{
int length = sensorcount;
largest = temperaturearray[0];
for(int i = 1; i < length; i++)
{
if(temperaturearray[i] > largest)
largest = temperaturearray[i];
}
Serial.print("length loop");
Serial.println(largest);
}
void gotofirstsensor()
{
Serial.println("make it to 1?");
myStepper.step(-STEPS);
myStepper.step(STEPS);
}
void gotosecondsensor()
{
Serial.println("make it to 2?");
myStepper.step(-STEPS);
myStepper.step(STEPS*2);
}
void gotothirdsensor()
{
Serial.println("make it to 3?");
myStepper.step(-STEPS);
myStepper.step(STEPS*3);
}
void gotofourthsensor()
{
Serial.println("make it to 4?");
myStepper.step(-STEPS);
myStepper.step(STEPS*4);
}
void gotofifthsensor()
{
Serial.println("make it to 5?");
myStepper.step(-STEPS);
myStepper.step(STEPS*5);
}
void gohome()
{
Serial.println("going home");
myStepper.step(-STEPS*1);
Serial.println("now at home");
}
float fillarray(float temperaturearray[])
{
sensors.requestTemperatures();
temperaturearray[0] = sensors.getTempC(Probe01);
temperaturearray[1] = sensors.getTempC(Probe02);
temperaturearray[2] = sensors.getTempC(Probe03);
temperaturearray[3] = sensors.getTempC(Probe04);
temperaturearray[4] = sensors.getTempC(Probe05);