Skip to content

Instantly share code, notes, and snippets.

@ulrichzwingli
Created December 2, 2017 03:53
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 ulrichzwingli/67f62b999cd210ab5f052de1d0eeea55 to your computer and use it in GitHub Desktop.
Save ulrichzwingli/67f62b999cd210ab5f052de1d0eeea55 to your computer and use it in GitHub Desktop.
FYF_Arduino_Code_Controlling_winch_shadow_p3
char val; // Data received from the serial port
int ledPin = 13; // Set the pin to digital I/O 13
//int servoVal = 0;
#include <Servo.h>
Servo servo1;
void setup() {
pinMode(ledPin, OUTPUT); // Set pin as OUTPUT
Serial.begin(9600); // Start serial communication at 9600 bps
servo1.attach(9);
}
void loop() {
if (Serial.available())
{ // If data is available to read,
int n1 = Serial.read();
int n = n1*4;
n = map(n,0,360,600,830);
// auto select appropriate value, copied from someone elses code.
//if(n1 >= 500)
{
//Serial.print("writing Microseconds: ");
Serial.print("angle: ");
Serial.println(n);
servo1.writeMicroseconds(n);
}
delay(10); // Wait 10 milliseconds for next reading
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment