2011年9月6日 星期二

Blinking_Lamp ( Arduino )







用基本的繼電器
配上旋鈕可變電阻作為
控制DELAY的時間
透過Arduino
產生檯燈開關閃爍的有趣形式

Use the Relay and Variable Resistor 
to control the "delay" of the Lamp.
Through the Arduino, it transfer the message 
to switch on and off of the LAMP


希望下一代能用伺服馬達
控制檯燈的彎曲度
使其成為跳舞的檯燈

Hope to control the Banding of the LAMP
through Arduino and Servo Motor
to make a DANCING LAMP//

the Arduino Code:
int val01 = 0; // Value From the Variable Resistor

int lampPin01 = 12;// output LAMP01
int lampPin02 = 11;// output LAMP02
int lampPin03 = 10;// output LAMP03

int inPin01 = 0;//Input Pin for the Variable Resistor

void setup() {                
  // initialize the digital pin as an output.
  Serial.begin(9600); 
  pinMode(lampPin01, OUTPUT);  
  pinMode(lampPin02, OUTPUT);    
  pinMode(lampPin03, OUTPUT);      
}

void loop() {
  val01 = analogRead(inPin01);    // read the value from the Variable Resistor

  Serial.println(val01);
  
  digitalWrite(lampPin01, HIGH);   // set the LAMP on
  delay(map(val01,0,1024,3,1000));            
  digitalWrite(lampPin02, HIGH);   // set the LAMP on
  delay(map(val01,0,1024,3,1000));           
  digitalWrite(lampPin03, HIGH);   // set the LAMP on
  delay(map(val01,0,1024,3,1000));           
  
  digitalWrite(lampPin03, LOW);    // set the LAMP off
  delay(map(val01,0,1024,3,1000));            
  digitalWrite(lampPin02, LOW);    // set the LAMP off
  delay(map(val01,0,1024,3,1000));         
  digitalWrite(lampPin01, LOW);    // set the LAMP off
  delay(map(val01,0,1024,3,1000));        
  }




沒有留言:

張貼留言