Arduino三色觸控燈

主辦單位:東區技術教學中心
協辦單位:花蓮高工教務處、花蓮高工實習處、花蓮學生開源社群(SOSCET)、本校機器人實驗室
主講人:郭德潤、林建川
實施地點:國立花蓮高工 資訊科
實施日期時間:104年12月6(日)上午08:40至下午16:00
參加人數:預計20人。
教師全程參與者登錄研習時數;學生全程參與者發給均質化研習證書。
課程表:  104年12月06日 (星期日)
 時間 活動議程 講師
08:40~09:00 報到/領取資料
09:00~9:50 Arduino 簡介、零件功能介紹 講師:郭德潤 助教:待聘
9:50-10:00 中場休息
10:00-10:50 閃爍吧 LED 講師:郭德潤 助教:待聘
10:50-11:00 中場休息
11:00-11:50 神燈! – 加上感應 講師:郭德潤 助教:待聘
11:50~13:00 午餐
13:00-13:50 焊接與製作 講師:林建川 助教:待聘
13:50-14:00 中場休息
14:00-14:50 焊接與製作 講師:林建川 助教:待聘
14:50-15:00 中場休息
15:00-15:50 偽裝? --讓燈光可以有顏色變化 講師:林建川 助教:待聘
15:50-16:00 賦歸




課程使用材料:
 Arduino 控制板
 RGB 三色LED ,參考資料
電阻器 150歐姆 X 2 ,200歐姆 X 1, 1K歐姆 X 1
 光敏電阻
 可變電阻
 麵包板






/*
 Fade

 This example shows how to fade an LED on pin 9
 using the analogWrite() function.

 This example code is in the public domain.
 */

int ledR = 9;           // the pin that the LED is attached to
int ledG = 10;           // the pin that the LED is attached to
int ledB = 11;           // the pin that the LED is attached to
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(ledR, OUTPUT);
  pinMode(ledG, OUTPUT);
  pinMode(ledB, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9:
//  analogWrite(ledR, brightness);
//  analogWrite(ledG, brightness);
  analogWrite(ledB, 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);
}





可變電阻 控制 RGB LED 亮度
從 Fade範例修改

/*
 Fade

 This example shows how to fade an LED on pin 9
 using the analogWrite() function.

 This example code is in the public domain.
 */

int ledR = 11;           // the pin that the LED is attached to
int ledG = 10;           // the pin that the LED is attached to
int ledB = 9;           // the pin that the LED is attached to
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(ledR, OUTPUT);
  pinMode(ledG, OUTPUT);
  pinMode(ledB, OUTPUT);
}

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

  // change the brightness for next time through the loop:
  brightness = analogRead(A0);

  // 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);
}