1
0
Fork 0
bescor-mp101-libre/arduino/wasd-ptz/wasd-ptz.ino

68 lines
1.8 KiB
C++

/*
wasd-ptz
WASD PTZ Control via Arduino of a Bescor MP101 Motorized Pan Head
Copyright (C) 2023, Jeff Moe
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// In main Arduino libraries
#include "Keyboard.h"
char inChar;
const int upPin = 1;
const int downPin = 2;
const int leftPin = 3;
const int rightPin = 0;
void setup() {
Serial.begin(9600);
Keyboard.begin();
}
void loop() {
if (Serial.available() > 0) {
char inChar = Serial.read();
if (inChar == 'w') {
Serial.println("Up");
digitalWrite(upPin,HIGH); digitalWrite(downPin,LOW);
}
if (inChar == 'a') {
Serial.println("Left");
digitalWrite(leftPin,HIGH); digitalWrite(rightPin,LOW);
}
if (inChar == 's') {
Serial.println("Down");
digitalWrite(upPin,LOW); digitalWrite(downPin,HIGH);
}
if (inChar == 'd') {
Serial.println("Right");
digitalWrite(leftPin,LOW); digitalWrite(rightPin,HIGH);
}
if (inChar == 'x') {
Serial.println("Stop");
digitalWrite(leftPin,LOW); digitalWrite(rightPin,LOW); digitalWrite(upPin,LOW); digitalWrite(downPin,LOW);
}
if (inChar == ' ') {
Serial.println("Stop");
digitalWrite(leftPin,LOW); digitalWrite(rightPin,LOW); digitalWrite(upPin,LOW); digitalWrite(downPin,LOW);
}
}
}