3路pwm波


#define R_PIN 4             //定义LED2灯引脚
#define G_PIN 0             //定义LED3灯引脚
#define B_PIN 2             //定义LED4灯引脚

int R_VAL=255;
int G_VAL=215;
int B_VAL=0;

void setup(){
  pinMode(R_PIN,OUTPUT);       //设定LED2引脚为输出
  pinMode(G_PIN,OUTPUT);       //设定LED3引脚为输出
  pinMode(B_PIN,OUTPUT);       //设定LED4引脚为输出
}

void loop(){

  analogWrite(R_PIN, 1023-R_VAL*4);//将255放大1023,再将1023变成0,1022变成1······//
  analogWrite(G_PIN, 1023-G_VAL*4);
  analogWrite(B_PIN, 1023-B_VAL*4);

}
image.png

你可能感兴趣的:(3路pwm波)