2014年11月24日 星期一

week11



範例程式:Hello Arduino: blink LED!
--------------------------------------------------------------------------------------------------------------------
/*
  AnalogReadSerial
  Reads an analog input on pin 0, prints the result to the serial monitor.
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

 This example code is in the public domain.
 */

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);        // delay in between reads for stability
}
--------------------------------------------------------------------------------------------------------------------
使用Arduino板子上的pin 13跟GND實作(Arduino板子已內建電阻)

Duemilanove、Diecimila and LilyPad已內建接在pin 13的LED燈

技巧1.小心PORT(硬體裝置管理員)
技巧2.Board要對(Tool-->Board-->型號)
技巧3.先Compile在Upload(燒入)
技巧4.燈泡正長負短,國字八左正右負,負-GND,正-13



霹靂燈
void setup(){
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
}
void loop(){
  digitalWrite(12, HIGH);
  delay(100);
  digitalWrite(12, LOW);
  digitalWrite(11, HIGH);
  delay(100);
  digitalWrite(11, LOW);
  digitalWrite(10, HIGH);
  delay(100);
  digitalWrite(10, LOW);
  digitalWrite(10, HIGH);
  delay(100);
  digitalWrite(10, LOW);
  digitalWrite(11, HIGH);
  delay(100);
  digitalWrite(11, LOW);
  digitalWrite(12, HIGH);
  delay(100);
  digitalWrite(12, LOW);
}
展示影片:


沒有留言:

張貼留言