2021年8月17日 星期二

pwm +1

 int pwm_led_pin=5;

int btn1_pin=2;

int btn2_pin=3;

int num1_val;

int num2_val;

int num;

void setup()

{

  pinMode(btn1_pin,INPUT);

  pinMode(btn2_pin,INPUT);

}


void loop()

{

 num1_val=digitalRead(btn1_pin);

 num2_val=digitalRead(btn2_pin);

 if(num1_val==LOW)

 {

  delay(50);

  while(digitalRead(btn1_pin)==LOW);

  analogWrite(pwm_led_pin,num=num+5);

 }

 if(num2_val==LOW)

 {

  delay(50);

  while(digitalRead(btn2_pin)==LOW);

  analogWrite(pwm_led_pin,num=num-5);

 }

}

沒有留言:

張貼留言

algorithm

 #include <iostream> #include <string.h> using namespace std; int main(int argc, char** argv)  { for(int j=2;j<=100;j++)//j...