Skip to content

Instantly share code, notes, and snippets.

@ulrichzwingli
Created January 16, 2018 04:38
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/8780e28a0a2f8edd172ef8a5d44a5cbf to your computer and use it in GitHub Desktop.
Save ulrichzwingli/8780e28a0a2f8edd172ef8a5d44a5cbf to your computer and use it in GitHub Desktop.
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