close
Blogtrottr
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中 
Explore DIRECTV

Enjoy HD DVR service in every room. Get every game every Sunday. Watch hit movies and shows anywhere. Bundle and save today!
From our sponsors
Arduino 基本程式問題
Apr 6th 2014, 23:42

你好: 有一個問題想很久還是想不出來,請有緣的朋友替我解答 感恩
Q.我要設計2顆led燈能呈現交替呼吸燈(一顆漸漸亮,另一顆漸漸暗)+透過電腦端的Serial Monitor 控制"呼吸"時間
目前2顆替換呼吸燈大概了解 主要控制呼吸燈時間程式該如何寫?(想破頭了)
以下是替換呼吸燈程式:

/* 交替呼吸燈 */

int led1 = 10; // the pin that the LED is attached to
int led2 = 11; // the pin that the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 10; // how many points to fade the LED by

// 此 setup 程序只有在微控制器按 reset 時執行一次
void setup() {
// declare pin 10 to be an output:
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
analogWrite(led1, brightness);
analogWrite(led2, 255-brightness);

// 透過迴圈改變下次的亮度值
brightness = brightness + fadeAmount;
// 進行邊界值的限制
if (brightness>255) brightness=255;
if (brightness<0) brightness=0;
// 判斷亮度值是否到達最小值或最大值
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// 為了方便觀察微量的亮度變化需延遲一小段時間
delay(30);
}

This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 marccmpt 的頭像
    marccmpt

    信貸利率, 個人信貸, 小額信貸, 信貸試算, 信貸銀行, 信貸條件, 信貸比較, 中國信託信貸, 公教信貸, 信貸利率最低

    marccmpt 發表在 痞客邦 留言(0) 人氣()