Skip to content

Instantly share code, notes, and snippets.

@lvidarte lvidarte/sketch.ino
Created Mar 26, 2015

Embed
What would you like to do?
Cannon laser client
#include <Servo.h>
#define SERVO_PIN 9
#define LASER_PIN 10
Servo myServo;
byte n;
int laser_active = 0;
void setup()
{
Serial.begin(9600);
myServo.attach(SERVO_PIN);
pinMode(LASER_PIN, OUTPUT);
}
void laser_on()
{
digitalWrite(LASER_PIN, HIGH);
laser_active = 1;
}
void laser_off()
{
digitalWrite(LASER_PIN, LOW);
laser_active = 0;
}
void laser_toggle()
{
if (laser_active) {
laser_off();
} else {
laser_on();
}
}
void laser_fire(int d)
{
laser_on();
delay(d);
laser_off();
}
void loop()
{
while (Serial.available() > 0) {
n = Serial.read();
switch (n)
{
case 181:
laser_on();
break;
case 182:
laser_off();
break;
case 183:
laser_toggle();
break;
case 184:
laser_fire(500);
break;
default:
myServo.write(n);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.