Advertisement
AntonioVillanueva

Control servo C++

May 9th, 2017
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. //g++ -o  camara  camara.cc -lwiringPi -lpthread
  2. #include <iostream>
  3. #include <wiringPi.h>
  4. #include <softPwm.h>
  5.  
  6. using namespace std;
  7. #define BARRIERE0 26//pwm0 BCM12 PIN 32
  8. #define INIT_VALUE 4//Valeur initial servo moteur
  9. #define RANGE 200//Valeur final servo moteur
  10.  
  11. int main (){
  12.     int degrees0(4);
  13.     int degrees1(4);
  14.  
  15.     if (wiringPiSetup()==-1 ) {cout <<"Erreur !"<<endl;return 1;}
  16.  
  17.     softPwmCreate(BARRIERE0,INIT_VALUE,RANGE);
  18.     delay(10);
  19.  
  20.     while (TRUE){
  21.         degrees0+=1;
  22.         cout<<degrees0<<endl;
  23.         if (degrees0>=26){degrees0=4;delay(2000);}
  24.         if (degrees0>RANGE/10 ){degrees0=3;}
  25.         softPwmWrite(BARRIERE0,degrees0);
  26.         delay(1000);
  27.  
  28.     }
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement