Skip to content

Instantly share code, notes, and snippets.

@proffalken
Created July 29, 2015 22:06
Show Gist options
  • Save proffalken/80332aa82368fed7571b to your computer and use it in GitHub Desktop.
Save proffalken/80332aa82368fed7571b to your computer and use it in GitHub Desktop.
/*
RC PulseIn Servos
By: Matthew Macdonald-Wallace
Date: 29/07/2015
HEAVILY BASED ON:
RC PulseIn Joystick
By: Nick Poole
SparkFun Electronics
Date: 5
License: CC-BY SA 3.0 - Creative commons share-alike 3.0
use this code however you'd like, just keep this license and
attribute. Let me know if you make hugely, awesome, great changes.
Original Article can be found at https://www.sparkfun.com/tutorials/348
*/
#include <Servo.h>
Servo lr;
Servo ud;
int ch1; // Here's where we'll keep our channel values
int ch2;
int ch3;
int lrval; // The value for the "Left/Right" Servo
int udval; // The value for the "Up/Down" Servo
void setup() {
pinMode(5, INPUT); // Set our input pins as such
pinMode(6, INPUT);
pinMode(7, INPUT);
lr.attach(10);
ud.attach(11);
Serial.begin(9600); // Pour a bowl of Serial
}
void loop() {
ch1 = pulseIn(5, HIGH, 25000); // Read the pulse width of
ch2 = pulseIn(6, HIGH, 25000); // each channel
ch3 = pulseIn(7, HIGH, 25000);
lrval = map(ch2, 1000, 2000, 0, 179);
lr.write(lrval);
udval = map(ch3, 1000, 2000, 0, 179);
ud.write(udval);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment