SHARE
TWEET

wtf

a guest Oct 16th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Servo.h>
  2. Servo myservo;
  3. int punled = 9;
  4. int kelled = 8;
  5. int vihled = 7;
  6. int nkiinni = 13;
  7. int nauki = 12;
  8. int pos = 0;
  9. int aukitila;
  10. int kiinnitila;
  11. String command;
  12.  
  13.  
  14.  
  15. void setup()
  16. {
  17.     Serial.begin(96000);
  18.     pinMode(punled, OUTPUT);
  19.     pinMode(kelled, OUTPUT);
  20.     pinMode(vihled, OUTPUT);
  21.     pinMode(nkiinni, INPUT);
  22.     pinMode(nauki, INPUT);
  23.     myservo.attach(3);
  24. aukitila = digitalRead(nauki);
  25. kiinnitila = digitalRead(nkiinni);
  26.   kiinni();
  27. }
  28.  
  29. void loop()
  30. {
  31. if(Serial.available()){
  32.         command = Serial.readStringUntil('\n');
  33.   if(command.equals("auki")){
  34.             auki();
  35.   }
  36.   else if(command.equals("kiinni")){
  37.             kiinni();
  38. }
  39.    else if(command.equals("Auki")){
  40.             auki();
  41. }
  42.    else if(command.equals("Kiinni")){
  43.             kiinni();
  44. }
  45. }
  46.  
  47.  
  48.  
  49.  
  50.   aukitila = digitalRead(nauki);
  51. kiinnitila = digitalRead(nkiinni);
  52.  if (aukitila == HIGH){
  53.   auki();}
  54.   if (kiinnitila == HIGH){
  55.   kiinni();}
  56. }
  57.  
  58.  
  59. void auki() {
  60.   pos = 180;
  61.     myservo.write(pos);            
  62.     delay(15);
  63.   liikkuu();
  64.   delay(250);
  65.   aukeaa();
  66.   }
  67.  
  68.  
  69. void kiinni() {
  70.   pos = 0;
  71.     myservo.write(pos);  
  72.   delay(15);
  73.   liikkuu();
  74.   delay(250);
  75.     sulkeutuu();
  76.   }
  77.  
  78.  
  79. void liikkuu(){
  80.   if ((myservo.read() <= 1) || (myservo.read() >=179)){
  81.     digitalWrite(kelled, HIGH);}
  82.      
  83. }
  84. void sulkeutuu(){
  85.   if (myservo.read() == 0){
  86.     Serial.println("portti on kiinni");
  87.   digitalWrite(vihled, LOW);
  88.   digitalWrite(punled, HIGH);
  89.     delay(400);
  90.     digitalWrite(kelled, LOW);
  91.    
  92.   }}
  93.   void aukeaa(){
  94.      if (myservo.read() == 180){
  95.     Serial.println("portti on auki");
  96.   digitalWrite(vihled, HIGH);
  97.   digitalWrite(punled, LOW);
  98.        delay(400);
  99.        digitalWrite(kelled, LOW);
  100.      }}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top