Skip to content

Instantly share code, notes, and snippets.

@soemarko
Last active September 27, 2019 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soemarko/536dd186c18da136c311c3b12ad0865e to your computer and use it in GitHub Desktop.
Save soemarko/536dd186c18da136c311c3b12ad0865e to your computer and use it in GitHub Desktop.
#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