botanoptical-code

Home   »   botanoptical-code

int pot = A0; //potentiometer
const int motorPin1 = 2; //h-bridge leg 1 (pin 2, 1A)
const int motorPin2 = 3; //h-bridge leg 2 (pin 7, 2A)
const int enablePin = 9; //h-bridge enable pin, pin 1

int sensorValuePotCurrent = 0;
int sensorValuePotPrev = 0;
int trend = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  sensorValuePotCurrent = analogRead(pot);
  Serial.println(sensorValuePotCurrent);
  delay(10);
//
  if(sensorValuePotCurrent > 850){ //center is 512 but want it to register when i turn potentiometer
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
  }
  else if(sensorValuePotCurrent < 400){
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, HIGH);
  }
  else{ //do nothing
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *