Skip to content

Instantly share code, notes, and snippets.

@virgilvox
Created September 21, 2023 19:50
Show Gist options
  • Save virgilvox/2844545e1a57fb9d3693458bd8e59967 to your computer and use it in GitHub Desktop.
Save virgilvox/2844545e1a57fb9d3693458bd8e59967 to your computer and use it in GitHub Desktop.
#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