Hi all,
I am at a loss and cannot figure this out.
I am working on a script that operates FastLED, two Mosfets, and an OLED, it is controlled via IRremote and Bluetooth via two Switchcase's. One of the "if" (first) statements controlling a mosfet is not triggering digitalWrite (digitalWrite(LEFTTAP, HIGH);). The hardware works when tested with nearly the exact timing code but without the other 2000+ lines of code. I have searched the rest of the code for any other mentions of "lefttap" without finding any. The mosfet pins can be reversed in the code - the second if statements always work, the first if statements work but do not appear to trigger the digitalwrite - the pin does not output with a measurable period using a good meter to test or the mosfet itself. I know the "if" statements are somewhat convoluted, but they do work, had I considered at the beginning how convoluted they would become, I probably would have used a switchcase or goto set.
I am using an Arduino framework on PlatformIO.
Serial output from the entire script:
Mode:
2
BUZZZ LEFT ON
19527
19527
BUZZZ LEFT OFF
end
currentMillis
19727
lastExecutedMillisLeft
19527
BUZZZ RIGHT ON
21103
21103
BUZZZ RIGHT OFF
end
currentMillis
21303
lastExecutedMillisLeft
19527
Pertinent portions of script (reduced for readability):
//In preamble:
#define RIGHTTAP 5
#define LEFTTAP 18
unsigned long lastExecutedMillis = 0;
unsigned long lastExecutedMillisRight;
unsigned long lastExecutedMillisLeft;
int m = 1;
int left_tap_state = LOW;
int right_tap_state = LOW;
int tap_side = LOW;
//In setup:
pinMode(RIGHTTAP, OUTPUT);
pinMode(LEFTTAP, OUTPUT);
//In loop:
unsigned long currentMillis = millis();
//Left Tapper (1) (Far End) Pin not going HIGH
if ((m >= 2) && (lead_dot == travel_distanceint-1) && (left_tap_state == LOW) && (right_tap_state == LOW) &&
(tap_side == LOW)){
lastExecutedMillisLeft = currentMillis;
left_tap_state = HIGH;
digitalWrite(LEFTTAP, HIGH); //Does not go HIGH
digitalWrite(LED_BUILTIN, HIGH);
Serial.println (" BUZZZ LEFT ON");
Serial.println("");
Serial.println(lastExecutedMillisLeft);
Serial.println("");
}
if ((left_tap_state == HIGH) && (right_tap_state == LOW) && (tap_side == LOW) &&
(currentMillis - lastExecutedMillisLeft >= 200)){
Serial.println(lastExecutedMillisLeft);
Serial.println("");
left_tap_state = LOW;
right_tap_state = LOW;
tap_side = HIGH;
digitalWrite(LEFTTAP, LOW); //?
digitalWrite(LED_BUILTIN, LOW);
Serial.println (" BUZZZ LEFT OFF");
Serial.println("end");
Serial.println("");
Serial.println ("currentMillis");
Serial.println(currentMillis);
Serial.println("");
Serial.println ("lastExecutedMillisLeft");
Serial.println(lastExecutedMillisLeft);
Serial.println("");
digitalWrite(LEFTTAP, LOW);
}
//Right Tapper (2) (closer to controller)
if ((m >= 2) && (lead_dot == 0) && (right_tap_state == LOW) &&
(left_tap_state == LOW) && (tap_side == HIGH)){
lastExecutedMillisRight = currentMillis;
right_tap_state = HIGH;
digitalWrite(RIGHTTAP, HIGH); //works
digitalWrite(LED_BUILTIN, HIGH);
Serial.println (" BUZZZ RIGHT ON");
Serial.println("");
Serial.println(lastExecutedMillisRight);
Serial.println("");
}
if ((right_tap_state == HIGH) && (left_tap_state == LOW) && (tap_side == HIGH) &&
(currentMillis - lastExecutedMillisRight >= 200)){
Serial.println(lastExecutedMillisRight);
Serial.println("");
right_tap_state = LOW;
tap_side = LOW;
digitalWrite(RIGHTTAP, LOW); //works
digitalWrite(LED_BUILTIN, LOW);
Serial.println (" BUZZZ RIGHT OFF");
Serial.println("end");
Serial.println("");
Serial.println ("currentMillis");
Serial.println(currentMillis);
Serial.println("");
Serial.println ("lastExecutedMillisLeft");
Serial.println(lastExecutedMillisLeft);
Serial.println("");
}
if (( m < 2) || (pausestate == 1)){
digitalWrite(LEFTTAP, LOW);
digitalWrite(RIGHTTAP, LOW);
left_tap_state = LOW;
right_tap_state = LOW;
digitalWrite(LED_BUILTIN, LOW);
}
Functional Test:
#include <Arduino.h>
#define LED_BUILTIN 27
#define RIGHTTAP 5
#define LEFTTAP 18
unsigned long lastExecutedMillis = 0;
unsigned long lastExecutedMillisRight;
unsigned long lastExecutedMillisLeft;
int left_tap_state = LOW;
int right_tap_state = LOW;
int tap_side = LOW;
void setup() {
pinMode(RIGHTTAP, OUTPUT);
pinMode(LEFTTAP, OUTPUT);
Serial.begin(115200);
}
void loop() {
unsigned long currentMillis = millis();
//Left Tapper
if ((left_tap_state == LOW) && (right_tap_state == LOW) && (tap_side == LOW)){
left_tap_state = HIGH;
lastExecutedMillisLeft = currentMillis;
digitalWrite(LEFTTAP, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
Serial.println (" BUZZZ LEFT ON");
Serial.println("");
Serial.println(lastExecutedMillisLeft);
Serial.println("");
}
else if ((left_tap_state == HIGH) && (right_tap_state == LOW) && (tap_side == LOW) &&
(currentMillis - lastExecutedMillisLeft >= 250)){
Serial.println(lastExecutedMillisLeft);
Serial.println("");
left_tap_state = LOW;
right_tap_state = LOW;
tap_side = HIGH;
digitalWrite(LEFTTAP, LOW);
digitalWrite(LED_BUILTIN, LOW);
Serial.println (" BUZZZ LEFT OFF");
Serial.println("end");
Serial.println("");
digitalWrite(LEFTTAP, LOW);
}
if ((right_tap_state == LOW) && (left_tap_state == LOW) && (tap_side == HIGH)){ //Right Tapper (closer to controller)
lastExecutedMillisRight = currentMillis;
right_tap_state = HIGH;
digitalWrite(RIGHTTAP, HIGH); //works
digitalWrite(LED_BUILTIN, HIGH);
Serial.println (" BUZZZ RIGHT ON");
Serial.println("");
Serial.println(lastExecutedMillisRight);
Serial.println("");
}
else if ((right_tap_state == HIGH) && (left_tap_state == LOW) && (tap_side == HIGH) &&
(currentMillis - lastExecutedMillisRight >= 250)){
Serial.println(lastExecutedMillisRight);
Serial.println("");
right_tap_state = LOW;
tap_side = LOW;
digitalWrite(RIGHTTAP, LOW);
digitalWrite(LED_BUILTIN, LOW);
Serial.println (" BUZZZ RIGHT OFF");
Serial.println("end");
Serial.println("");
}
Serial.println("LED Travel");
Serial.println("");
}
Thanks for reading this far:)