Instantly share code, notes, and snippets.

Embed
What would you like to do?
Face your fear _ Arduino code
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