SG90

28 views
Skip to first unread message

joseph

unread,
Jun 8, 2017, 11:24:39 PM6/8/17
to IT_Project
/*
 *  Created on: 2016年2月5日
 *      Author: ro...@ittraining.com.tw
 */

#include <bcm2835.h>
#include "it_shield.h"

int main (void)
{
    if (!bcm2835_init())
   return ;


           bcm2835_gpio_fsel(PWM0,BCM2835_GPIO_FSEL_ALT5); //set gpio for PWM0


           bcm2835_pwm_set_clock(1920);   //set min frequence =19.2M/1920
           bcm2835_pwm_set_mode(0,1,1);   //(channel,PWM0 MSEN enable , PWM0 enable)
           bcm2835_pwm_set_range(0,200);  //set period=20ms
 
  while (1)
       {
             static int a;
          for(a=5;a<=20;a++)
                   { 
                    bcm2835_pwm_set_data(0,a);    //set pulse width 
                   delay(100000);
                   }
                   for(a=20;a>=5;a--)
                   { 
                    bcm2835_pwm_set_data(0,a);    //set pulse width 
                   delay(100000);
                   }
                   
        }
     
           
    bcm2835_close();
    return 0;
}



joseph

unread,
Jun 8, 2017, 11:27:04 PM6/8/17
to IT_Project


joseph於 2017年6月9日星期五 UTC+8上午11時24分39秒寫道:
servo.rar
Reply all
Reply to author
Forward
0 new messages