Use Toy Gun Play Game
I wanted to make a toy gun to power and I decided to use the Arduino that I am familiar with.Please refer to the Youtube link for the operation video.
Supplies
- Leonardo、Esplora、Zero、Due or MKR choose
- electric wire
- micro switch*2
- Precision resistor
Circuit
Connect the circuit according to the circuit diagram.
After completing this, connect GND to D4.
Program
enter code
---------------------------------------------------------------------------------------------------------------------------------------------------------------
#include <Mouse.h>
#include <Keyboard.h>
void setup(){
pinMode( 5 , INPUT); // sets the digital pin as input
Mouse.begin(); // initialize control over the mouse
pinMode( 6 , INPUT); // sets the digital pin as input
Keyboard.begin(); // initialize control over the keyboard
Keyboard.releaseAll();
}
void loop(){ // put your main code here, to run repeatedly:
if (digitalRead( 5 )) {
pinMode(4,INPUT_PULLUP); //make pin 4 an input and turn on the pullup resistor so it goes high unless connected to ground
if(digitalRead(4)==LOW){ // do nothing until pin 4 goes low
Mouse.click(MOUSE_LEFT);
}
}
if (digitalRead( 6 )) {
pinMode(4,INPUT_PULLUP); //make pin 4 an input and turn on the pullup resistor so it goes high unless connected to ground
if(digitalRead(4)==LOW){ // do nothing until pin 4 goes low
Keyboard.press('r'); //the key to press (ASCII code)
}
delay( 500 ); // waits a few milliseconds
Keyboard.releaseAll();
}
}
Downloads
Shell
You just make a gun ,you can make a pistol too.Remember to dig holes for the wires to pass through.