1. 使用 Maker Uno板子做開發 -->供應商 宇宙XXX
2.需要下載驅動程式 網址:https://makeruno.com.my/getting-started/
3. 馬力歐音效程式 (開機時的聲音)
CODE:
#define NOTE_C5 523 #define NOTE_E5 659 #define NOTE_G5 784 #define BUTTON 2 #define BUZZER 8 int melody[] = { NOTE_E5, NOTE_E5, 0, NOTE_E5, 0, NOTE_C5, NOTE_E5, 0, NOTE_G5 }; int noteDurations[] = { 10, 10, 10, 10, 10, 10, 10, 10, 10 }; int pin; int ledArrayHigh; int ledArrayLow; boolean mode = false; boolean buttonPressed = false; void setup() { delay(1000); pinMode(BUTTON, INPUT_PULLUP); for (pin = 3; pin < 14; pin++) { pinMode(pin, OUTPUT); } for (int thisNote = 0; thisNote < 9; thisNote++) { int noteDuration = 1000 / noteDurations[thisNote]; tone(BUZZER, melody[thisNote], noteDuration); int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); noTone(BUZZER); } } void loop() { for (pin = 0; pin < 5; pin++) { if (digitalRead(BUTTON) == LOW && buttonPressed == false) { buttonPressed = true; mode = !mode; pin = 0; if (mode == false) { tone(BUZZER, NOTE_C5, 100); delay(100); tone(BUZZER, NOTE_G5, 100); delay(100); noTone(BUZZER); } else if (mode == true) { tone(BUZZER, NOTE_G5, 100); delay(100); tone(BUZZER, NOTE_C5, 100); delay(100); noTone(BUZZER); } } if (mode == false) { ledArrayHigh = 13 - pin; ledArrayLow = 7 - pin; } else if (mode == true) { ledArrayHigh = 9 + pin; ledArrayLow = 3 + pin; } digitalWrite(ledArrayHigh, HIGH); digitalWrite(ledArrayLow, HIGH); delay(100); digitalWrite(ledArrayHigh, LOW); digitalWrite(ledArrayLow, LOW); if (pin == 4) delay(100); } if (buttonPressed == true) { buttonPressed = false; } }
沒有留言:
張貼留言