2019年6月3日 星期一

PWM











































































boolean pushBtn1;
boolean pushBtn2;
#define ledPin 9
int brightness =128;
int delaytime=1000;
void setup()
{
  // put your setup code here, to run once:
 pinMode(2,INPUT_PULLUP);
 pinMode(3,INPUT_PULLUP);
 pinMode(ledPin,OUTPUT);
 Serial.begin(9600);
}

void loop()
{
  // put your main code here, to run repeatedly:
  pushBtn1=digitalRead(2);
  pushBtn2=digitalRead(3);
  if(!pushBtn1 && brightness >0)
  {
    brightness=brightness-5;
  }
  else if(!pushBtn1 && brightness <255)
  {
    brightness=brightness+5;
  }
  analogWrite(ledPin,brightness);
  Serial.println(brightness);
  delay(1000);
}













沒有留言:

張貼留言

algorithm

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