Skip to content

Instantly share code, notes, and snippets.

@kkevlar
Created July 22, 2018 03:25
Show Gist options
  • Save kkevlar/5ca802aef45b860f505c3aaf6e8d1c97 to your computer and use it in GitHub Desktop.
Save kkevlar/5ca802aef45b860f505c3aaf6e8d1c97 to your computer and use it in GitHub Desktop.
#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