Use Toy Gun Play Game

by ryan106084 in Circuits > Arduino

204 Views, 1 Favorites, 0 Comments

Use Toy Gun Play Game

5EAC4A13-770D-4DCD-A9D0-C1EB446F6E62.jpeg
8FC5CB4D-B87D-4C8B-9D91-691669B65628.jpeg
7B59AEE3-2054-43FE-8BFE-C6D212E9057C.jpeg
Use Arduino make a Scar-L for 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

  1. Leonardo、Esplora、Zero、Due or MKR choose
  2. electric wire
  3. micro switch*2
  4. Precision resistor

Circuit

擷取.JPG

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();
 }
}

Shell

0A37FDB5-9E24-4FB5-9FE2-36EEB3FBC663.jpeg
76FFB241-AD85-41E8-8C62-84D93D9C8FB6.jpeg
19414C86-B958-4995-999D-F25017A81E91.jpeg
BDBD4FB0-B13A-405C-B7E9-79677D21D3BC.jpeg
4A962F38-0548-437A-A796-96822210E309.jpeg
5E8D1388-7B38-4E68-9791-0F95746AD89A.jpeg
241CAF98-78FF-4CCF-962E-19480BC12157.jpeg
7345CD3E-81B4-4413-9744-6504D5979B3B.jpeg
A829E927-7EA9-4F48-906A-138739A96763.jpeg
C3276B9E-9D81-498E-A8F0-D9A0DAED4AC0.jpeg
D442BB3C-44DB-4411-A8BC-E7BA41541472.jpeg

You just make a gun ,you can make a pistol too.Remember to dig holes for the wires to pass through.