Skip to content

Instantly share code, notes, and snippets.

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/fa6fb4413a1bf06c2d5e7b210eed8377 to your computer and use it in GitHub Desktop.
Save ulrichzwingli/fa6fb4413a1bf06c2d5e7b210eed8377 to your computer and use it in GitHub Desktop.
Project : Face Your Fear (Arduino code for processing controlling servo)
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(9);
}
void loop() {
if (Serial.available())
{ // If data is available to read,
val = Serial.read(); // read it and store it in val
}
servo1.write(2*int(val)); // turn the LED on
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