Created
July 22, 2018 03:25
-
-
Save kkevlar/5ca802aef45b860f505c3aaf6e8d1c97 to your computer and use it in GitHub Desktop.
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
#include <Servo.h> | |
Servo myservo; // create servo object to control a servo | |
void setup() | |
{ | |
Serial.begin(9600); | |
myservo.attach(9); // attaches the servo on pin 9 to the servo object | |
} | |
void shot(float amount) | |
{ | |
myservo.write(135); | |
delay((850 * 3 * amount)+200); | |
myservo.write(135-90); | |
} | |
char buf[100]; | |
int indx; | |
void shot_and_delay(float amount) | |
{ | |
shot(amount); | |
} | |
void loop() | |
{ | |
while(Serial.available()) | |
{ | |
buf[indx] = Serial.read(); | |
indx++; | |
} | |
if(strncmp(buf, "drank", 5) == 0) | |
{ | |
shot_and_delay(1); | |
indx = 0; | |
memset(buf, 0 , 5); | |
} | |
delay(100); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment