Created
November 12, 2015 21:10
-
-
Save bassdread/a8e3cc77063e3177a337 to your computer and use it in GitHub Desktop.
Arduino Gong
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
// Sweep | |
// by BARRAGAN <http://barraganstudio.com> | |
// This example code is in the public domain. | |
#include <Servo.h> | |
Servo myservo; // create servo object to control a servo | |
// a maximum of eight servo objects can be created | |
int pos = 0; // variable to store the servo position | |
String inputString = ""; // a string to hold incoming data | |
boolean stringComplete = false; // whether the string is complete | |
void setup() | |
{ | |
myservo.attach(10); // attaches the servo on pin 9 to the servo object | |
myservo.write(90); | |
// initialize serial: | |
Serial.begin(9600); | |
// reserve 200 bytes for the inputString: | |
inputString.reserve(200); | |
} | |
void loop() | |
{ | |
if (stringComplete && inputString == "gong\n") { | |
Serial.println(inputString); | |
// tell servo to go to position in variable 'pos' | |
// waits 15ms for the servo to reach the position | |
myservo.write(140); | |
delay(100); | |
myservo.write(40); | |
delay(5000); | |
myservo.write(90); | |
//myservo.write(0); | |
//myservo.write(90); | |
inputString = ""; | |
stringComplete = false; | |
} | |
} | |
void serialEvent() { | |
while (Serial.available()) { | |
// get the new byte: | |
char inChar = (char)Serial.read(); | |
// add it to the inputString: | |
inputString += inChar; | |
// if the incoming character is a newline, set a flag | |
// so the main loop can do something about it: | |
if (inChar == '\n') { | |
stringComplete = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment