2018年11月15日 星期四

W10 陳泓丞的課堂筆記

N01

測試 Arduino 板子,把 Arduino 接上電腦,並下載驅動

網站 https://makeruno.com.my/getting-started/



下載驅動



下載完畢



若下載成功可以到電腦的裝置管理員確認




接下來即可上網查詢範例程式檢測板子有無問題

我所查詢的範例程式為 Melody 即讓 Arduino 播放小蜜蜂

int speakerPin = 8;     //此處網路上原為9,但我們是紫色板子,故改8

int length = 15; // the number of notes
char notes[] = "ccggaagffeeddc "; // a space represents a rest
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;

void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}

void playNote(char note, int duration) {
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

  // play the tone corresponding to the note name
  for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);
    }
  }
}

void setup() {
  pinMode(speakerPin, OUTPUT);
}

void loop() {
  for (int i = 0; i < length; i++) {
    if (notes[i] == ' ') {
      delay(beats[i] * tempo); // rest
    } else {
      playNote(notes[i], beats[i] * tempo);
    }

    // pause between notes
    delay(tempo / 2); 
  }
}

完成後按下 " 驗證 " 再按 " 上傳 "



有聲音即為成功

沒有留言:

張貼留言