Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wesk/d71f467309913462ff1110a988dc983f to your computer and use it in GitHub Desktop.
Save wesk/d71f467309913462ff1110a988dc983f to your computer and use it in GitHub Desktop.
integrated linear actuator and flipper control
/*
*
* LINEAR ACTUATOR & FLIPPER PROGRAM CONTROL!
further modified 19 May 2016, Thayer ENGS21 proj, Wes Kendrick.
Using grove shield,
modified even more for the linear actuator 5/25/2016
CONFIG!!!
servo wired to D7
switch to D5
//potentiometer is wired into A0. Note that the cable, as it is currently configured, is screwed up, need jumper cables
//brown == ground; red = power, orange == signal.
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
//int pos = 0; // variable to store the servo position
//CONSTANTS FOR EZ CONFIGURATION!!!
const int DI_button_pin=8;
const int servo = 7;
//put the linear actuator motor control cable in the grove slot labled D2. Don't switch up the orientation
const int purple = 2;
const int grey = 3;
bool go;
bool reached;
int counter;
void setup() {
myservo.attach(7); // attaches the servo on pin 7 to the servo object
pinMode(DI_button_pin,INPUT);
digitalWrite(DI_button_pin,HIGH); ///////that super strange line that fixes stuff
pinMode(purple,OUTPUT);
pinMode(grey,OUTPUT);
Serial.begin(9600);
myservo.write(160);
digitalWrite(purple,LOW);
digitalWrite(grey,LOW);
go = false;
reached = false;
counter = 0;
}
void loop() {
Serial.println(digitalRead(DI_button_pin));
if(digitalRead(DI_button_pin)==LOW){
//extend till reaches
int counter = 0;
while((analogRead(A0) < 900) && counter < 1000){
digitalWrite(purple,HIGH);
digitalWrite(grey,LOW);
counter = counter + 1;
//delay(1);
}
delay(500);
myservo.write(0);
delay(300);
//retract
while(analogRead(A0) > 200){
digitalWrite(purple,HIGH);
digitalWrite(grey,HIGH);
}
delay(500);
myservo.write(160);
delay(500); // To give time for the flipper to move up and in between the pages before the finger retracts
digitalWrite(purple,LOW);
digitalWrite(grey,LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment