Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
arduin steppers
const int leftButtonPin = 2; // the number of the pushbutton pin
int leftButtonState = 0, lastLeftButtonState = 0; // variable for reading the pushbutton status
const int rightButtonPin = 3; // the number of the pushbutton pin
int rightButtonState = 0, lastRightButtonState = 0; // variable for reading the pushbutton status
const int analogInPinRightP1 = A5;
const int analogInPinLeftP1 = A4;// Analog input pin that the potentiometer is attached to
int sensorValueRightP1 = 0;
int sensorValueLeftP1 = 0;// value read from the pot
boolean leftonP1 = false;
boolean rightonP1 = false;
const int analogInPinRightP2 = A3;
const int analogInPinLeftP2 = A2;// Analog input pin that the potentiometer is attached to
int sensorValueRightP2 = 0;
int sensorValueLeftP2 = 0;// value read from the pot
boolean leftonP2 = false;
boolean rightonP2 = false;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(57600);
pinMode(A5, INPUT_PULLUP);
pinMode(A4, INPUT_PULLUP);
pinMode(A3, INPUT_PULLUP);
pinMode(A2, INPUT_PULLUP);
pinMode(leftButtonPin, INPUT);
pinMode(rightButtonPin, INPUT);
}
void loop() {
// read the analog in value:
sensorValueRightP1 = analogRead(analogInPinRightP1);
sensorValueLeftP1 = analogRead(analogInPinLeftP1);
sensorValueRightP2 = analogRead(analogInPinRightP2);
sensorValueLeftP2 = analogRead(analogInPinLeftP2);
leftButtonState = digitalRead(leftButtonPin);
rightButtonState = digitalRead(rightButtonPin);
//Serial.println(sensorValueRightP1);
if(sensorValueLeftP1 < 30 && !leftonP1) {
// digitalWrite(13, HIGH);
Serial.print("1l,");
Serial.println(sensorValueLeftP1);
leftonP1 = true;
} else if(sensorValueLeftP1 > 30 && leftonP1) {
leftonP1 = false;
Serial.print("1l,");
Serial.println(200);
}
if(sensorValueRightP1 < 30 && !rightonP1) {
Serial.print("1r,");
Serial.println(sensorValueRightP1);
rightonP1 = true;
} else if(sensorValueRightP1 > 30 && rightonP1) {
rightonP1 = false;
Serial.print("1r,");
Serial.println(200);
}
if(sensorValueLeftP2 < 30 && !leftonP2) {
Serial.print("2l,");
Serial.println(sensorValueLeftP2);
leftonP2 = true;
} else if(sensorValueLeftP2 > 30 && leftonP2) {
leftonP2 = false;
Serial.print("2l,");
Serial.println(200);
}
if(sensorValueRightP2 < 30 && !rightonP2) {
Serial.print("2r,");
Serial.println(sensorValueRightP2);
rightonP2 = true;
} else if(sensorValueRightP2 > 30 && rightonP2) {
rightonP2 = false;
Serial.print("2r,");
Serial.println(200);
}
if (leftButtonState == HIGH && lastLeftButtonState != HIGH) {
Serial.println("x0");
}
if (rightButtonState == HIGH && lastRightButtonState != HIGH) {
Serial.println("x1");
}
lastLeftButtonState = leftButtonState;
lastRightButtonState = rightButtonState;
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.