2016年12月27日 星期二

define

#define a 13  //#define 變數名稱  接腳值
void setup() {
  // put your setup code here, to run once:
            Serial.begin(9600);
            Serial.println(a);
}
------------------------------------------
int x=2;
int y=6;
#define k 2*x*y    //#define 變數名稱  運算式
-------------------------------------
#define 函數名稱(參數)  運算式

#define d(x) 5*x
void setup() {
  // put your setup code here, to run once:
            Serial.begin(9600);
            Serial.println(d(3));
}

#define d(x,y) 2*x*y
void setup() {
  // put your setup code here, to run once:
            Serial.begin(9600);
            Serial.println(d(3,2));
}
-----------------------------------------------------

3~,5~,6~,9~,10~,11~,脈衝寬頻信號  類比可接

三色Led燈
int b=9;
int g=10;
int r=11;

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
  int bv=0;
  int gv=0;
  int rv=0;
 for(bv=1;bv<=255;bv++)
  {
      analogWrite(b,bv);
      delay(10);
  }
   for(bv=255;bv>=0;bv--)
  {
      analogWrite(b,bv);
      delay(10);
  }
   for(gv=1;gv<=255;gv++)
  {
      analogWrite(g,gv);
      delay(10);
  }
   for(gv=255;gv>=0;gv--)
  {
      analogWrite(g,gv);
      delay(10);
  }
   for(rv=1;rv<=255;rv++)
  {
      analogWrite(r,rv);
      delay(10);
  }
   for(rv=255;rv>=0;rv--)
  {
      analogWrite(r,rv);
      delay(10);
  }
  for(int i=0;i<=100;i++)
  {
    rv=random(1,30);
    gv=random(1,20);
    bv=random(1,50);
    analogWrite(r,rv);
    analogWrite(g,gv);
    analogWrite(b,gv);                        
  }
    analogWrite(r,0);  //歸零  關燈
    analogWrite(g,0);
    analogWrite(b,0);
}
=============================
int led=13;
int pirout=2;
void setup() {
  // put your setup code here, to run once:
  pinMode(led,OUTPUT);
  pinMode(pirout,INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
    int val=digitalRead(pirout);
    if(val==HIGH)
    {
      digitalWrite(led,HIGH);
      delay(3000);
      digitalWrite(led,LOW);
      delay(2000);
    }
    else
    {
      digitalWrite(led,LOW);
    }
}
=============================
ledBar
int ledbar[10]={4,5,6,7,8,9,10,11,12,13};
void cleared()
{
  for(int k=0;k<10;k++)
  {
    digitalWrite(ledbar[k],LOW);
  }
}
void setup() {
  // put your setup code here, to run once:
              for(int i=0;i<10;i++)
              {
                pinMode(ledbar[i],OUTPUT);
              }
}

void loop() {
  // put your main code here, to run repeatedly:
    for(int j=0;j<10;j++)
    {
      cleared();
      digitalWrite(ledbar[j],HIGH);
      delay(50);
         }
      for(int j=10;j>0;j--)
    {
      cleared();
      digitalWrite(ledbar[j],HIGH);
      delay(50);
         }
}
========================================
int ledbar[10]={4,5,6,7,8,9,10};
const int cr=A0;

void cleared()
{
  for(int k=0;k<7;k++)
  {
    digitalWrite(ledbar[k],LOW);
  }
}
void setup() {
  // put your setup code here, to run once:
              for(int i=0;i<7;i++)
              {
                pinMode(ledbar[i],OUTPUT);
              }
}

void loop() {
  // put your main code here, to run repeatedly:
  int crv=analogRead(cr);
  int mcrv=map(crv,0,1023,0,6);
  cleared();
 
    for(int j=0;j<mcrv;j++)
    {
     
      digitalWrite(ledbar[j],HIGH);
     delay(500);
         }
   
}

1 則留言:

  1. MGM Resorts, Limited - JT Hub
    Las Vegas casino and resort features a 5-star accommodation with amenities like 보령 출장마사지 concierge, an 경상남도 출장마사지 outdoor 하남 출장안마 pool and 포천 출장마사지 an indoor pool. Guests can enjoy a swim in 군산 출장마사지 the

    回覆刪除