// car 🚙 with gun 🔫 shooting
#include<Servo.h>
Servo myservoX;
Servo myservoY;
// for joy stick
int pinx = A0;
int piny = A1;
int pins = 2;
// for both servo
int xser=9;
int yser=10;
// for light and buzzer
int ledpin = 7;
// for servo pos , and calculation
int wvx;
int wvy;
// for get joy-stick value and make calculetion
int velx;
int vely;
int vels;
void setup() {
Serial.begin(9600);
pinMode(pinx, INPUT);
pinMode(piny, INPUT);
pinMode(pins, INPUT);
pinMode(xser, OUTPUT);
pinMode(yser, OUTPUT);
pinMode(ledpin, OUTPUT);
myservoX.attach(xser);
myservoY.attach(yser);
digitalWrite(pins, HIGH);
// put your setup code here, to run once:
}
void loop() {
//read the value from the joy-stick
velx = analogRead(pinx);
wvx = ((180./1023.)*velx); // in this i forgot point (180.)
vely = analogRead(piny);
wvy = ((180./1023.)*vely); // in this i forgot point (180.)
vels= digitalRead(pins);
// control servo
myservoX.write(wvx);
myservoY.write(wvy);
// for light and buzzer (to use press the joy-stick) shoot the target 🔫
if(vels == 0){
digitalWrite(ledpin, HIGH);
delay(10);
}
if(vels == 1){
digitalWrite(ledpin, LOW);
delay(10);
}
// for printing the value of joy stick
Serial.print(" velue x = ");
Serial.print(velx);
Serial.print(", velue y = ");
Serial.print(vely);
Serial.print(", velue s = ");
Serial.println(vels);
// delay time ⌚
delay(200);
// put your main code here, to run repeatedly:
}