I'm having a sporadic issue that goes away when I include a Serial print.The machine normally has nothing connected to the Serial port; I am only using it for debugging and initial programming. When I press the Start button on the machine (or 'FaultResetButton'), it will print several messages to serial than start the machine after a 150 millisecond delay. However, if I comment out: "Serial.print(F("StartChanged "))" it will skip all the Serial prints after the debounce and immediately start the motor. Sometimes, it wont even start the motor. I find it very strange that the Serial print must be included even if nothing is connected to the port. Any Suggestions?
void StartStop()
{
/////________ Start _________/////
int Startreading = digitalRead(FaultResetButton);
if (Startreading != LastStartReading)
{
lastDebounceTime = millis();
StartState = 1;
//Serial.print(F("StartChanged ")); //<-- MUST BE PRESENT
}
if (StartState == 1 && (millis() - lastDebounceTime) > debounceDelay)
{
if (MachineStopped == 1)
{
if (digitalRead(FaultResetButton) == LOW && DownstreamJam == 0)
{
Serial.print(F("Start - "));
RunState = 1;
StartState = 0;
MachineStopped = 0;
BoxIsWiped = 0;
Zone1Wiped = 0;
Zone2Wiped = 0;
lastEntryPEState = digitalRead(EntryPE);
lastExitPEState = digitalRead(ExitPE);
EntryPEState = lastEntryPEState;
ExitPEState = lastExitPEState;
LastTopCounts = TopCounts;
LastBottomCounts = BottomCounts;
Serial.print(F("RunState: "));
Serial.println(RunState);
delay(150);
if (MachineSetup != 20)
{
digitalWrite(UpstreamConveyor, HIGH);
MotorState = 1;//StartMotors
Serial.println(F("motorRun"));
}
BoxState = 0;
}
if (MotorState != lastMotorState)
{
digitalWrite(MotorRelayPin, MotorState);
Serial.println(F("MOTORSTATE CHANGED"));
lastMotorState = MotorState;
}
}
ELECDIAMSD.pdf (31.6 KB)
BPduino_AS1c.ino (13.9 KB)
BP_Variables.h (5.13 KB)