Created
September 21, 2023 19:50
-
-
Save virgilvox/2844545e1a57fb9d3693458bd8e59967 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
Servo yservo; | |
Servo xservo; | |
#define LASER_PIN 3 | |
#define X_PIN 10 | |
#define Y_PIN 9 | |
void setup() { | |
Serial.begin(9600); | |
yservo.attach(Y_PIN); | |
xservo.attach(X_PIN); | |
pinMode(LASER_PIN, OUTPUT); | |
} | |
void loop() { | |
while (Serial.read() != '$') ; // Wait for $ | |
int laser = Serial.parseInt(); | |
int x = Serial.parseInt(); | |
int y = Serial.parseInt(); | |
setPosition(x, y); | |
if(laser == 1){ | |
laserOn(); | |
}else { | |
laserOff(); | |
} | |
} | |
void laserOn() { | |
digitalWrite(LASER_PIN, HIGH); | |
} | |
void laserOff() { | |
digitalWrite(LASER_PIN, LOW); | |
} | |
void setPosition(int x, int y) { | |
yservo.write(y); | |
xservo.write(x); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment