Hi everyone,
Im currently working on a arduino controlled mosfet for my airsoftDMR. I have a cycle sensor cuttoff) that clicks everytime the gun cycles 1 time along with a trigger button and a relay to activate the mosfet.
I've been trying to make a program that looks for the trigger button to be pressed. As that happens, the relay must click 'ON' until the cycle sensor detects a full rotation of the gearbox. As soon as the firing cycle is completed, i want the arduino to turn OFF the relay even if the trigger button is still pressed. Once i release the trigger button and press it again, i want the cycle to fire once again
The trigger button gives a HIGH output along with the cycle detection button.
I've tried many diferent solutions and havent got to make it work
If you guys have any guidance that would be great!
const int triggerPin = 3;
const int cutoffPin = 5;// the number of the pushbutton pin
const int relayPin = 2;
const int ledPin = 13;// the number of the LED pin
// variables will change:
int triggerState = 0; // variable for reading the pushbutton status
int cutoffState = 0;
int lastTriggerState = 0;
int relayState = 0;
void setup() {
pinMode(relayPin, OUTPUT);
pinMode(triggerPin, INPUT);
pinMode(cutoffPin, INPUT);
}
void loop() {
triggerState = digitalRead(triggerPin);
cutoffState = digitalRead(cutoffPin);
if(triggerState != lastTriggerState){
if (triggerState == HIGH) {
digitalWrite(relayPin, HIGH);
}
if (cutoffState == HIGH) {
digitalWrite(relayPin, LOW);
delay(50);
lastTriggerState = triggerState;
}
}
}
g36.ino (1.37 KB)