Lucas garage

garage door and lights

 

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int potPin = A0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin
int inPin = A1;  //lampa
int ljusPin = 8; 
int ljudPin = 7;  //ljud
int outlightPin = 5;  //ytterljus

void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  pinMode(ljusPin, OUTPUT);  //lampa
  pinMode(ljudPin, OUTPUT);  //ljud
  pinMode(outlightPin, OUTPUT);  //ytterljus
}

void loop() 
{ 
  val = analogRead(potPin);  // reads the value of the potentiometer 
  val = map(val, 0, 1023, 0, 90);     // scale it to use it with servo
  myservo.write(val);                 // sets the servo position 
  delay(15);                           // waits for the servo
  
  int inpinValue = analogRead(inPin);    //lampa
  int potpinValue = analogRead(potPin);  //ljud
  
  if(inpinValue <= 500){                  //lampa börjar
    digitalWrite(ljusPin, HIGH);
    }
    
  else{
    digitalWrite(ljusPin, LOW);            //lampa slutar
    }
    
  if(potpinValue >= 100){          //ljud
    tone(ljudPin, 300, 5);
    delay(50);
    tone(ljudPin, 350, 5);
    digitalWrite(outlightPin, HIGH);  //ytterljus
    }
    
  else{
    digitalWrite(outlightPin, 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 )

Facebook photo

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

Connecting to %s