一段 PWM 控制液晶背光亮度的代码

发布于: 28 January, 2014
分享:
int pwm_id = 0;
int delay_us = 200000;
int freq = 781; //HZ
int value = 0;

void setup()
{
  int step = 0;
  step = pwmfreq_set(pwm_id, freq);
  printf("PWM%d set freq %d and valid duty cycle range [0, %d]\n", pwm_id, freq, step);
  if (step > 0)
  {
    printf("PWM%d test with duty cycle %d\n", pwm_id, value);
    analogWrite(pwm_id, value);
  }
}

void loop()
{
  value += 5;
  if (MAX_PWM_LEVEL < value) value = 0;
  delayMicroseconds(delay_us);
  printf("PWM%d test with ducy cycle %d\n", pwm_id, value );
  analogWrite(pwm_id, value);
}

 

分享:

0 留言

留言

您的留言将被人工审核,请勿发表色情、反动言论。