I removed all the case switches, tried to keep the code minimal, case 1 and 0. still same effect on power up.
#define DEBUG 1 // turn On (1) or Off (0) Serial.print & Serial.println
#if DEBUG == 1
#define debug(x) Serial.print(x)
#define debugln(x) Serial.println(x)
#else
#define debug(x)
#define debugln(x)
#endif
// Defines Inputs
int ParkPin = 2; // Ground when @ Park
int HighPin = A1; // High Input - Circuit 92
int DelayPin = A0; // Input via different resistive values - Circuit 93
// Defines Outputs
const int LowOutputPin = 12; // LowSpeed out
const int HighOutputPin = 6; // HighSpeed out
const int WasherOutputPin = 5; // Washer Pump Out
int PosVal = 0;
int OldPosVal = 0;
int count = 0; // Set count to zero
int LastCount = 0; // To reset count back to zero
int D1 = 6500; // 500 Delay approx 12 seconds with serial print on, 6500
int D2 = 5500; // 400 Delay approx 9.5 seconds, 5500
int D3 = 4500; // 300 Delay approx 7.5 seconds, 4400
int D4 = 3500; // 200 Delay approx 4.75 seconds, 3500
int D5 = 1500; // 100 Delay approx 2.5 seconds, 1500
int D6 = 80; // Delay for code to wait before exiting case #
const int D7 = 50; // Button Debounce press delay. Used cont int since it got rid of the warning below. code ran, just tried to get rid of warning
//warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
//if(millis() - lastReading >= D7)
// ~~~~~~~~~~~~~~~~~~~~~~~^~~~~
unsigned long previousMillis = 0;
unsigned long currentMillis;
int LowPin() // Value displayed with current resistors installed 957
{
if (analogRead(DelayPin) >= 900 && analogRead(DelayPin) <= 970) { // Value displayed is 958
return 1;
}
else {
return 0;
}
}
int Highrequest() // Value displayed with current resistors installed 957
{
if (analogRead(HighPin) >= 950 ) { // Value displayed is 1023
return 1;
}
else {
return 0;
}
}
int WasherPin() // Value displayed with current resistors installed 1023
{
if (analogRead(DelayPin) >= 1000) { // && analogRead(DelayPin) <= 25) {
return 1;
}
else {
return 0;
}
}
int DelaySpeed1() // Value displayed with current resistors installed 21 +/- 1
{
if (analogRead(DelayPin) >= 18 && analogRead(DelayPin) <= 30) {
return 1;
}
else {
return 0;
}
}
int DelaySpeed2() // Value displayed with current resistors installed approx 42 +/- 1
{
if (analogRead(DelayPin) >= 35 && analogRead(DelayPin) <= 55) {
return 1;
}
else {
return 0;
}
}
int DelaySpeed3() // Value displayed with current resistors installed approx 72 +/- 1
{
if (analogRead(DelayPin) >= 65 && analogRead(DelayPin) <= 85) {
return 1;
}
else {
return 0;
}
}
int DelaySpeed4() // Value displayed with current resistors installed approx 144 +/- 1
{
if (analogRead(DelayPin) >= 130 && analogRead(DelayPin) <= 155) {
return 1;
}
else {
return 0;
}
}
int DelaySpeed5() // Value displayed with current resistors installed 290 +/- 1
{
if (analogRead(DelayPin) >= 260 && analogRead(DelayPin) <= 300) {
return 1;
}
else {
return 0;
}
}
bool WasherState = 0;
bool ParkState = 0;
bool LowState = 0;
bool DelayState1 = 0;
bool DelayState2 = 0;
bool DelayState3 = 0;
bool DelayState4 = 0;
bool DelayState5 = 0;
bool HighState = 0;
void setup()
{
Serial.begin(115200);
debugln("+++++ Wiper Selection +++++");
// Initialize the pins as an input:
pinMode(ParkPin, INPUT_PULLUP);
pinMode(HighPin, INPUT);
pinMode(DelayPin, INPUT);
// Initialize the pins as an output:
pinMode(LowOutputPin, OUTPUT);
pinMode(HighOutputPin, OUTPUT);
pinMode(WasherOutputPin, OUTPUT);
}
void loop()
{
static unsigned long lastReading = 0;
if(millis() - lastReading >= D7)
{
lastReading = millis();
ParkState = digitalRead(ParkPin);
HighState = Highrequest();
LowState = LowPin();
WasherState = WasherPin();
DelayState1 = DelaySpeed1();
DelayState2 = DelaySpeed2();
DelayState3 = DelaySpeed3();
DelayState4 = DelaySpeed4();
DelayState5 = DelaySpeed5();
}
PosVal = (!ParkState * 1) + (LowState * 2) + (HighState * 4) + (WasherState * 8) + (DelayState1 * 16) + (DelayState2 * 32) + (DelayState3 * 64) + (DelayState4 * 128) + (DelayState5 * 256); // calculate Position selected
if (PosVal != OldPosVal)
{
debugln();
debug ("Park Signal = ");
debug (ParkState);
debug (" Low Signal = ");
debug (LowState);
debug (" High Signal = ");
debug (HighState);
debug (" Washer Signal = ");
debugln(WasherState);
debug ("DelaySpeed1 = ");
debug (DelaySpeed1());
debug (" DelaySpeed2 = ");
debug (DelaySpeed2());
debug (" DelaySpeed3 = ");
debug (DelaySpeed3());
debug (" DelaySpeed4 = ");
debug (DelaySpeed4());
debug (" DelaySpeed5 = ");
debug (DelaySpeed5());
debug (" PosVal # ");
debugln(PosVal);
debug ("Count @ ");
debugln (count);
debug ("A0 Signal value @ ");
debugln(analogRead(DelayPin));
debug ("A2 High value @ ");
debugln(Highrequest());
switch (PosVal)
{
case 1:
count = LastCount; // Resets count value for next cycle
debugln("OFF Selected");
digitalWrite(LowOutputPin, HIGH); // Continue movement till ParkPin is grounded
digitalWrite(HighOutputPin, LOW);
digitalWrite(WasherOutputPin, LOW);
break;
case 0:
count = LastCount; // Resets count value for next cycle
debugln("PARK Selected"); //Switch turned to Off and Wiper Motor ParkPin grounded
digitalWrite(LowOutputPin, LOW);
digitalWrite(HighOutputPin, LOW);
digitalWrite(WasherOutputPin, LOW);
break;
// default:
// debugln("Invalid Selection");
// digitalWrite(LowOutputPin, LOW);
// digitalWrite(HighOutputPin, LOW);
break;
}
}
OldPosVal = PosVal;
}
More trouble shooting, Pin 12 is the one that is activating for a split second on boot-up.
Pin12 will also activate for the same split second when serial monitor window is opened.
I swapped:
// Defines Outputs
const int LowOutputPin = 12; // LowSpeed out
const int HighOutputPin = 6; // HighSpeed out
const int WasherOutputPin = 5; // Washer Pump Out
to
// Defines Outputs
const int LowOutputPin = 6; // LowSpeed out
const int HighOutputPin = 12; // HighSpeed out
const int WasherOutputPin = 5; // Washer Pump Out
to see if the position of output is effected, The first output is pin6, then pin12 and pin12 is the one that flashed... so order of outputs doesnt effect it.
when prototyping the board on the Uno rev3, pin 13 did something similar on startup, so I used a different pin.. Maybe pin12 is not a good output pin.
Also tested on a genuine Nano, exact same results.