Created
December 2, 2017 03:53
-
-
Save ulrichzwingli/67f62b999cd210ab5f052de1d0eeea55 to your computer and use it in GitHub Desktop.
FYF_Arduino_Code_Controlling_winch_shadow_p3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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