Skip to content

Instantly share code, notes, and snippets.

@wesk
Last active May 28, 2016 18:30
Show Gist options
  • Save wesk/e6206c75adb91ca3ba5b9ec0467b57b3 to your computer and use it in GitHub Desktop.
Save wesk/e6206c75adb91ca3ba5b9ec0467b57b3 to your computer and use it in GitHub Desktop.
arduino code for our engs 21 16S project
/*
*
* 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(0);
digitalWrite(purple,LOW);
digitalWrite(grey,LOW);
go = false;
reached = false;
counter = 0;
}
void loop() {
int buttonValue=digitalRead(DI_button_pin);
Serial.println(buttonValue);
if(buttonValue==LOW){
go = true;
reached = false;
}
int potentiometerValue = analogRead(A0);
if(go){
counter++;
if(counter > 500 && reached == false){
reached = true;
}
if(potentiometerValue <= 1020 && reached == false){
digitalWrite(purple,HIGH);
}
if(potentiometerValue >= 1000){
reached = true;
}
if(reached && potentiometerValue >= 100){
digitalWrite(purple,HIGH);
digitalWrite(grey,HIGH);
}
if(potentiometerValue <=200 && reached == true){
go = false;
digitalWrite(purple,LOW);
digitalWrite(grey,LOW);
counter = 0;
}
}
delay(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment