2016年11月21日 星期一

Week12 劉柏廷


更新驅動程式,並檢察連接阜。



參考exmple 2-2 BUTTON 製作

///需要使用 10歐姆電阻



更新後的簡單程式碼
(當按下之後會發亮)

/*
void setup()
{
  pinMode(13,OUTPUT);
  pinMode(2,INPUT);
}

void loop()
{
   int result =digitalRead(2);
   if(result == HIGH) digitalWrite(13,HIGH);
   else digitalWrite(13,LOW);
  
}

*/


線路圖





Example 2-4
簡易線路版本


 void setup()
{
  pinMode(13,OUTPUT);
  pinMode(2,INPUT_PULLUP);
}

void loop()
{
   int result =digitalRead(2);
   if(result == HIGH) digitalWrite(13,LOW);
   else digitalWrite(13,HIGH);

}



********
感光元件 使用

  Analog Input
/*

int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);  
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);    
  // turn the ledPin on
  digitalWrite(ledPin, HIGH);  
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);          
  // turn the ledPin off:        
  digitalWrite(ledPin, LOW);   
  // stop the program for for <sensorValue> milliseconds:
  delay(sensorValue);                  
}

*/越暗燈亮越快




沒有留言:

張貼留言