Created
January 16, 2018 04:38
-
-
Save ulrichzwingli/8780e28a0a2f8edd172ef8a5d44a5cbf to your computer and use it in GitHub Desktop.
Face your fear _ Arduino code
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 | |
#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(10); | |
} | |
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