Created
November 20, 2017 06:24
-
-
Save ulrichzwingli/fa6fb4413a1bf06c2d5e7b210eed8377 to your computer and use it in GitHub Desktop.
Project : Face Your Fear (Arduino code for processing controlling servo)
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(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