Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.00 KB | None | 0 0
  1.  
  2. #include <Wire.h>
  3. #include <Servo.h>
  4.  
  5. int fotorezystorgora = 5;
  6. int fotorezystordol = 4;
  7. int fotorezystorprawo = 3;
  8. int fotorezystorlewo = 2;
  9. float pomiarnapiecia = 1;
  10.  
  11. int fot1 = 0;
  12. int fot2 = 0;
  13. int fot3 = 0;
  14. int fot4 = 0;
  15. float napiecie = 0;
  16.  
  17.  
  18.  
  19. Servo serwomechanizm1;
  20. Servo serwomechanizm2;
  21.  
  22. int pozycja = 0; //Aktualna pozycja serwa 0-180
  23.  
  24. void setup()
  25. {
  26.   pinMode(fotorezystorgora, INPUT);
  27.   pinMode(fotorezystordol, INPUT);
  28.   pinMode(fotorezystorprawo, INPUT);
  29.   pinMode(fotorezystorlewo, INPUT);
  30.   pinMode(pomiarnapiecia, INPUT);
  31.   Serial.begin(9600);
  32.  
  33.  
  34.   serwomechanizm1.attach(9);  //Serwomechanizm podłączony do pinu 9
  35.   serwomechanizm2.attach(10);  //Serwomechanizm podłączony do pinu 9
  36. }
  37.  
  38. void loop (){
  39.  
  40.   fot1 = analogRead(fotorezystorgora);
  41.   fot1 = map(fot1, 0,1023, 0,180);
  42.   Serial.print("gora: ");
  43.   Serial.print(fot1);
  44.   Serial.print("   ");
  45.  
  46.   fot2 = analogRead(fotorezystordol);
  47.   fot2 = map(fot2, 0,1023, 0,180);
  48.   Serial.print("dol: ");
  49.   Serial.print(fot2);
  50.   Serial.print("   ");
  51.  
  52.   fot3 = analogRead(fotorezystorprawo);
  53.   fot3 = map(fot3, 0,1023, 0,180);
  54.   Serial.print("prawo: ");
  55.   Serial.print(fot3);
  56.   Serial.print("   ");
  57.  
  58.   fot4 = analogRead(fotorezystorlewo);
  59.   fot4 = map(fot4, 0,1023, 0,180);
  60.   Serial.print("lewo: ");
  61.   Serial.print(fot4);
  62.   Serial.print("   ");
  63.  
  64.   Serial.println("   ");
  65.  
  66.   if(fot1>fot2){
  67.     gora();  
  68.   }
  69.  
  70.   else if (fot2>fot1){
  71.     dol();
  72.   }
  73.   else{
  74.     srodek();
  75.   }
  76.  
  77.  
  78.   if(fot3>fot4){
  79.     prawo();  
  80.   }
  81.  
  82.   else if (fot3<fot4){
  83.     lewo();
  84.   }
  85.   else{
  86.     srodek2();
  87.   }
  88.  
  89.  
  90.  
  91.   delay(1000);
  92.   }
  93.  
  94.  
  95.  
  96.   void gora(){
  97.     serwomechanizm1.write(45);
  98.   }
  99.  
  100.   void dol() {
  101.     serwomechanizm1.write(135);
  102.   }
  103.  
  104.   void prawo() {
  105.     serwomechanizm2.write(0);
  106.   }  
  107.  
  108.   void lewo() {
  109.     serwomechanizm2.write(177);
  110.   }
  111.  
  112.   void srodek() {
  113.    serwomechanizm1.write(90);
  114.   }
  115.  
  116.   void srodek2() {
  117.    serwomechanizm2.write(90);
  118.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement