luke lock


Fritzing kopplingsschema

luke lock

image created with fritzing


 Arduino koden

int pot1 = A0;
int pot2 = A1;
int pot3 = A2;
int pot4 = A3;
int solenoidPin = 11;
int greenPin = 12;
int redPin = 13;

void setup() 
{
  // no need for pinMode on pots, it´s INPUT by default
  Serial.begin(9600);   // for debugging only
  pinMode(solenoidPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(redPin, OUTPUT);
}

void loop() {
  
  int pot1Val = analogRead(pot1);
  int pot2Val = analogRead(pot2);
  int pot3Val = analogRead(pot3);
  int pot4Val = analogRead(pot4);
  
  Serial.println(pot1Val);
  Serial.println(pot2Val);
  Serial.println(pot3Val);
  Serial.println(pot4Val);
  delay(400);
  
  if(pot1Val<= 150 && pot1Val >= 80 && pot2Val<= 150 && pot2Val >= 80 && pot3Val<= 150 && pot3Val >= 80 && pot4Val<= 150 && pot4Val >= 80)
  {
    digitalWrite(greenPin, HIGH);
    digitalWrite(solenoidPin, HIGH);
    digitalWrite(redPin, LOW);
  }
  
  else
  {
    digitalWrite(redPin, HIGH);
    digitalWrite(greenPin, LOW);
    digitalWrite(solenoidPin, LOW);
  }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s