Help with code - 2 input switches controlling 1 output. UNO to ATtiny85

HELLO!

If input_1 is LOW, output_0 is LOW. If input_1 is HIGH, output_0 is HIGH, BUT WAIT! There is an input_2.

THE PROBLEM Start - I am attempting to have input_1 turn on output_0, and while input_1 is HIGH and output_0 is HIGH, do the following; always start at "zero" and count HIGH button presses from input_2, after "5" HIGH button presses from input_2, turn output_0 off(LOW) until input_1 is released(turns LOW). If input_1 happens to turn LOW at anytime, the count is reset and output_0 turns LOW and we go back to the start.

My results- I have been manipulating example "stateChangeDetection" and can only get the output_0 to turn HIGH with input_2, and input_1 acts as a on/off switch for input_2. This result is undesirable and any help would be greatly appreciated.

CODE: // this constant won't change: const int trigPin = 2; const int resetPin = 4; const int fetPin = 0;

// Variables will change: int buttonPushCounter = 0; // counter for the number of button presses int buttonState = 0; // current state of the button int lastButtonState = 0; // previous state of the button

void setup() { pinMode(resetPin, INPUT); pinMode(trigPin, INPUT); pinMode(fetPin, OUTPUT); }

void loop() { if (digitalRead(trigPin) == HIGH) { buttonState = digitalRead(resetPin); if (buttonState != lastButtonState) { // compare the buttonState to its previous state if (buttonState == HIGH) { // if the state has changed, increment the counter buttonPushCounter++; // if the current state is HIGH then the button went from off to on: } else { } } lastButtonState = buttonState; if (buttonPushCounter % 5 == 0) { digitalWrite(fetPin, LOW); } else { digitalWrite(fetPin, HIGH); } delay(1); } else { digitalWrite(fetPin, LOW); } } //end

  if (digitalRead(trigPin) == HIGH) {

How is the trigPin switch wired? What happened to state change detection?

      else {
      }

Why? Your code would be easier to read if: Every { was on a new line Every } was on a new line You had used Tools + Auto Format You had posted it correctly.

hi PaulS,

thank you for the reply. Auto format - check.

PaulS:   if (digitalRead(trigPin) == HIGH) {

How is the trigPin switch wired? What happened to state change detection?

      else {
      }

Why? Your code would be easier to read if: Every { was on a new line Every } was on a new line You had used Tools + Auto Format You had posted it correctly.

For the switches, "pull down type" with vcc connected to switch connected to input-pin and I am using 10K Ohm resistors connected from input pin to ground. Output for testing purposes is a 200Ohm resistor in series with an led.

As far as "stateChangeDetection" goes, I found the closest example that "counted" using button presses. I honestly have no formal code training and this approach could be the worst possible way to preform the desired operations. Please advise! I am eager to learn from an expert willing to teach.