- 註冊時間
- 2008-2-26
- 最後登錄
- 2024-6-16
- 主題
- 查看
- 積分
- 43
- 閱讀權限
- 20
- 文章
- 30
- 相冊
- 1
- 日誌
- 1

狀態︰
離線
|
Arduino真是很好玩的一個板子,今天剛收到立馬來實驗看看。
程式碼:
//雷射筆Arduino版本,只裝訊號、接地線。
static int ledStatus;
static unsigned long lastDebounceTime;
void setup()
{
Serial.begin(115200);
pinMode(2, INPUT);
pinMode(13, OUTPUT);
ledStatus = LOW;
digitalWrite(13, ledStatus);
}
void updateLed()
{
unsigned long currentTime = millis();
if((currentTime - lastDebounceTime) > DEBOUNCE_DELAY)
{
lastDebounceTime = currentTime;
ledStatus = ledStatus == HIGH ? LOW : HIGH;
digitalWrite(13, ledStatus);
Serial.println(ledStatus);
}
}
void loop()
{
int switchStatus = digitalRead(2);
if(switchStatus == HIGH)
{
updateLed();
}
}
|
|