2020年1月30日 星期四

pwm 來回

const int led[] = {3, 5, 6, 9, 10, 11};
int x = 0;
int change = 0;
int delaytime = 1;
void setup()
{
  // put your setup code here, to run once:
  for (int i = 0; i < 6; i++)
  {
    pinMode(led[i], OUTPUT);
  }
}
void loop()
{
  // put your main code here, to run repeatedly:
  if (change == 0)
  {
    for (int i = 0; i < 256; i++)
    {
      analogWrite(led[x], i); delay(delaytime);
    }
    for (int i = 254; i >= 0; i--)//led真的關掉,才不會有微亮
    {
      analogWrite(led[x], i); delay(delaytime);
    }
    x++;
    if (x == 6)
    {
      x = 4;//......回來要從第5顆回來
      change=1;
    }
  }
  else if(change==1)
  {
    for (int i = 0; i < 256; i++)
    {
      analogWrite(led[x], i); delay(delaytime);
    }
    for (int i = 254; i >= 0; i--)//led真的關掉,才不會有微亮
    {
      analogWrite(led[x], i); delay(delaytime);
    }
    x--;
    if (x == 0)
    {
      x = 0;
      change=0;
    }
  }
}

沒有留言:

張貼留言

algorithm

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