/*Made by Berend Koedam tuesday 5 may 2022.
This project is not complete in the simulation,
because it is not possible to attach somthing to the servo.
if you want to make it IRL you will need to attach the side of the servo on top of the other servos axis.
This way one servo moves the X axis and the other the Y axis.
and the LED can be hooked up to anything example: cannon/laser.
Good luck.
*/
//Librarys
#include <Servo.h>
//Pins
const byte switchPin = A0;
const byte Fire = 2;
const byte HPin = A1;
const byte VPin = A2;
//Sets up the servos
Servo HorizontalServo;
Servo VerticalServo;
void setup()
{
//Sets the pins to INPUT
pinMode(switchPin, INPUT);
pinMode(HPin, INPUT);
pinMode(VPin, INPUT);
//Attaches the servo PWM pins
HorizontalServo.attach(5);
VerticalServo.attach(6);
}
void loop()
{
//Read the joystick value
int HOR = analogRead(HPin);
int VER = analogRead(VPin);
//Convert the value to 180 for the servos
HOR = map(HOR, 0, 1023, 0, 180);
VER = map(VER, 0, 1023, 0, 180);
//Sends the signal to the servos
HorizontalServo.write(HOR);
VerticalServo.write(VER);
//Checks and fires the Led/cannon IRL
if(digitalRead(switchPin) == HIGH)
{
digitalWrite(Fire, HIGH);
}
else if(digitalRead(switchPin) == LOW)
{
digitalWrite(Fire, LOW);
}
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
servo1:GND
servo1:V+
servo1:PWM
servo2:GND
servo2:V+
servo2:PWM
joystick1:VCC
joystick1:VERT
joystick1:HORZ
joystick1:SEL
joystick1:GND
led1:A
led1:C