2017年11月14日 星期二

Arduino the first time


1. Connect Arduino to MacBook by USB prot
2. Launch Arduino IDE


It will be auto-discovery 

Select connect com port



Pin A0-A5: Analog import
Digital: 0V - 5V?
TX/RX: 外部BT
L: LED pin 13
AT328P chip: 大腦


LED 長腳接+: Pin 13
Load Blink template:


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(200);                       // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second


Practice

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
  digitalWrite(12, LOW);  // turn the LED off by making the voltage LOW
  delay(500);             // wait for a second
  digitalWrite(13, LOW);
  digitalWrite(12, HIGH);
  delay(500);             // wait for a second


}

Pracetice: 呼吸燈


int led = 9;           // the PWM pin the LED is attached to Pin 9具備 PWM功能
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}

Notes: 0->255 then 255 -> 0 呼吸cycle


Practice:可變電阻



Practice: 感應式互動光源



沒有留言:

張貼留言

check_systemv1.1

 check_systemv1.1.bat 可用於電腦資產盤點 @echo off REM 後續命令使用的是:UTF-8編碼 chcp 65001 echo ***Thanks for your cooperation*** echo ***感謝你的合作*** timeout 1...