The Duino tagger isn't my project. That's IR tag and what I'm making is a simpler laser shooting gallery. I don't think its the audio causing the problem either as that's dealt with by the separate ISD1820 audio board and just receives the signal from the Arduino.
I've included the code below and, in full auto, the code is 116 milliseconds long so its roughly 8.6 times a second.
I can buy parts from wherever but I use easyeda then JLCPCB so I'm reckon I'd try to get SMD resistors, MOSFETs and Gate Drivers pre-installed when I get new boards. I'd probably move to a Arduino Pro Micro too to save space.
const int alignPin = 4; // laser alignment switch pin no.
const int triggerPin = 5; // trigger button pin no.
const int recoilPin = 6; // recoil pin no.
const int laserPin = 7; // laser pin no.
const int audioPin = 8; // Audio pin no.
const int RotSwitch1 = 9; // 1/3 rotary switch position
const int RotSwitch2 = 10; // 2/3 rotary switch position
const int RotSwitch3 = 11; // 3/3 rotary switch position
int triggerState = 0; // variable for reading the trigger status
int alignState = 0; // variable for the align pin/ switch
int RotSwitch1State = 0; // variable for the Rotary switch 1 pin for single shot
int RotSwitch2State = 0; // variable for the Rotary switch 2 pin for 3 shot burst
int RotSwitch3State = 0; // variable for the Rotary switch 3 pin for full auto
void setup()
{
pinMode(triggerPin, INPUT); // initialize the pushbutton pin as an input
pinMode(alignPin, INPUT); //initialize the align pin as an input
pinMode(laserPin, OUTPUT); // initialize the laser pin as an output
pinMode(recoilPin, OUTPUT); //initialize the recoil pin as an output
pinMode(audioPin, OUTPUT); // initialise the audio pin as an output
pinMode(RotSwitch1, INPUT_PULLUP); //initialize the rotary switch pin 1 as an input and enable the internal pull-up resistor
pinMode(RotSwitch2, INPUT_PULLUP); //initialize the rotary switch pin 2 as an input and enable the internal pull-up resistor
pinMode(RotSwitch3, INPUT_PULLUP); //initialize the rotary switch pin 3 as an input and enable the internal pull-up resistor
}
void loop()
{
triggerState = digitalRead(triggerPin); // read the state of the pushbutton value
alignState = digitalRead(alignPin); // read the state of the alignment switch
RotSwitch1State = digitalRead(RotSwitch1); //read the state of rotary switch pin 1
RotSwitch2State = digitalRead(RotSwitch2); //read the state of rotary switch pin 2
RotSwitch3State = digitalRead(RotSwitch3); //read the state of rotary switch pin 3
// SINGLE SHOT FIRING SEQUENCE
if (triggerState == HIGH and alignState == LOW and RotSwitch1State == LOW) // Determine when trigger is pressed, its on single shot and alignment switch is off
{
delay(6); //UIPM 6ms barrel time delay
digitalWrite(laserPin, HIGH); digitalWrite(recoilPin, HIGH); digitalWrite(audioPin, HIGH); // turn Laser, recoil and audio on
delay(20); //wait 20 ms. UIPM standards are 15.6ms and 25.2ms
digitalWrite(laserPin, LOW); //laser off
delay(40);
digitalWrite(recoilPin, LOW);digitalWrite(audioPin, LOW);// recoil and audio off
delay(684); //This means the whole 'shot' sequence is approx. 0.75 second long. Audio file is 1 second long. Should also mean the gun won't double fire as easily without having to use debounce
while(triggerState == HIGH and alignState == LOW) // should mean the gun should only fire once per trigger pull
{
triggerState = digitalRead(triggerPin);
alignState = digitalRead(alignPin);
digitalWrite(laserPin, LOW); digitalWrite(recoilPin, LOW); digitalWrite(audioPin, LOW);
}
}
// 3 SHOT FIRING SEQUENCE
else if (triggerState == HIGH and alignState == LOW and RotSwitch2State == LOW) // Determine when trigger is pressed, its on 3 shot burst and alignment switch is off
{
delay(6); //UIPM 6ms barrel time delay
digitalWrite(laserPin, HIGH); digitalWrite(recoilPin, HIGH); digitalWrite(audioPin, HIGH); // turn Laser, recoil and audio on
delay(20); //wait 20 ms. UIPM standards are 15.6ms and 25.2ms
digitalWrite(laserPin, LOW); //laser off
delay(40);
digitalWrite(recoilPin, LOW);digitalWrite(audioPin, LOW);// recoil and audio off
delay(50);
digitalWrite(laserPin, HIGH); digitalWrite(recoilPin, HIGH); digitalWrite(audioPin, HIGH); // turn Laser, recoil and audio on
delay(20); //wait 20 ms. UIPM standards are 15.6ms and 25.2ms
digitalWrite(laserPin, LOW); //laser off
delay(40);
digitalWrite(recoilPin, LOW);digitalWrite(audioPin, LOW);// recoil and audio off
delay(50);
digitalWrite(laserPin, HIGH); digitalWrite(recoilPin, HIGH); digitalWrite(audioPin, HIGH); // turn Laser, recoil and audio on
delay(20); //wait 20 ms. UIPM standards are 15.6ms and 25.2ms
digitalWrite(laserPin, LOW); //laser off
delay(40);
digitalWrite(recoilPin, LOW);digitalWrite(audioPin, LOW);// recoil and audio off
while(triggerState == HIGH and alignState == LOW and RotSwitch2State == LOW) // should mean the gun should only fire once per trigger pull
{
triggerState = digitalRead(triggerPin);
alignState = digitalRead(alignPin);
digitalWrite(laserPin, LOW); digitalWrite(recoilPin, LOW); digitalWrite(audioPin, LOW);
}
}
// CONTINUOUS FIRING SEQUENCE
else if (triggerState == HIGH and alignState == LOW and RotSwitch3State == LOW) // Determine when trigger is pressed, its on Auto and alignment switch is off
{
delay(6); //UIPM 6ms barrel time delay
digitalWrite(laserPin, HIGH); digitalWrite(recoilPin, HIGH); digitalWrite(audioPin, HIGH); // turn Laser, recoil and audio on
delay(20); //wait 20 ms. UIPM standards are 15.6ms and 25.2ms
digitalWrite(laserPin, LOW); //laser off
delay(40);
digitalWrite(recoilPin, LOW);digitalWrite(audioPin, LOW);// recoil and audio off
delay(50);
}
// CALIBRATION CODING
else if (alignState == HIGH) //is alignment switch on for calibration?
{digitalWrite(laserPin, HIGH);} //if yes, laser gets turned on constantly}
else (alignState == LOW);
{ digitalWrite(laserPin, LOW);}
}