Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <Servo.h>
int endstopPin = 7;
int val = 0;
Servo s;
int servoPin = 9;
int stowAngle = 30;
int deployAngle = 160;
char serialIn = ' ';
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Serial ready... send 's' to stow and 'd' to deploy");
pinMode(LED_BUILTIN, OUTPUT);
pinMode(endstopPin, INPUT);
s.attach(servoPin);
s.write(stowAngle);
}
// the loop function runs over and over again forever
void loop() {
val = digitalRead(endstopPin);
digitalWrite(LED_BUILTIN, val);
if (Serial.available() > 0) {
serialIn = (char)Serial.read();
if (serialIn == 's') {
Serial.println("Stow");
s.write(deployAngle);
}
else if (serialIn == 'd') {
Serial.println("Deploy");
s.write(deployAngle);
}
}
}
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.