2018互動技術

2018年11月22日 星期四

week11

播歌
void setup() {
  for(int i=2;i<=13;i++){
    pinMode(i, OUTPUT);
  }
}

void loop() {
  for(int i=2;i<=13;i++){
    digitalWrite( i, HIGH);
    delay(300);
  }
  for(int i=2;i<=13;i++){
    digitalWrite( i, LOW);
  }

}int piezoPin = 8;
int length = 15;
char notes[] = "ccggaag ffeeddc ggffeed ggffeed ccggaag ffeeddc ";      // 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(piezoPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(piezoPin, 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 };
  for (int i = 0; i < 8; i++)
  {
    if (names[i] == note)
    {
      playTone(tones[i], duration);
    }
  }
}

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

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

於 11月 22, 2018
以電子郵件傳送這篇文章BlogThis!分享至 X分享至 Facebook分享到 Pinterest
標籤: 05160815_吳彥輝

沒有留言:

張貼留言

較新的文章 較舊的文章 首頁
訂閱: 張貼留言 (Atom)

標籤

  • 03373640_劉薇忻 (12)
  • 04160453_蔡明諺 (15)
  • 04160515_廖葆棠 (15)
  • 04162646_王浩晉 (13)
  • 04162691_林俐妏 (16)
  • 04211021_馬紹芸 (16)
  • 04370423_廖宜德 (4)
  • 04372600_吳宇凡 (11)
  • 05160053_甘珮妤 (15)
  • 05160080_黃惠嘉 (16)
  • 05160213_黃登煜 (15)
  • 05160222_郭宇傑 (18)
  • 05160240_潘昱霖 (16)
  • 05160311_彭立欣 (16)
  • 05160354_汪育玄 (16)
  • 05160372_林彥甫 (11)
  • 05160390_宋偉榤 (11)
  • 05160425_陳亭光 (13)
  • 05160486_武煜川 (16)
  • 05160495_周良峰 (13)
  • 05160523_朱紘希 (11)
  • 05160541_胡哲愷 (13)
  • 05160593_余杰恩 (13)
  • 05160630_阮致峰 (17)
  • 05160655_羅聖閔 (10)
  • 05160664_黃柏穎 (14)
  • 05160673_林敬諺 (14)
  • 05160753_林郁珊 (16)
  • 05160780_宋侑恩 (16)
  • 05160806_陳怡瑄 (16)
  • 05160815_吳彥輝 (15)
  • 05160974_夏玉庭 (14)
  • 05160992_劉沛潔 (13)
  • 05161040_黃玟褱 (14)
  • 05161102_沈哲民 (12)
  • 05161111_陳示珮 (16)
  • 05161120_徐譽嘉 (16)
  • 05161145_洪毓謙 (15)
  • 05161163_鄭岢庭 (8)
  • 05161172_鄭昕恬 (16)
  • 05161181_梁傳宗 (9)
  • 05161190_李宜謙 (10)
  • 05161200_蔡宜君 (5)
  • 05161216_焦奕維 (13)
  • 05163012_楊芩瑜 (16)
  • 05163021_江家宜 (13)
  • 05163046_陳泓丞 (11)
  • 05163064_徐如君 (16)
  • 05163073_黃科凱 (16)
  • 05163082_劉峻宇 (12)
  • Week01 (44)
  • Week02 (43)
  • Week03 (27)
  • week04 (27)
  • week05 (25)
  • week06 (27)
  • week07 (23)
  • Week08 (23)
  • week09 (3)
  • Week10 (23)
  • Week11 (27)
  • week12 (20)
  • Week13 (21)
  • Week14 (20)
  • Week15 (16)
  • week16 (15)
  • Week17 (15)
  • weel04 (1)

網誌存檔

  • 1月 2019 (69)
  • 12月 2018 (134)
  • 11月 2018 (125)
  • 10月 2018 (178)
  • 9月 2018 (136)
簡單主題. 技術提供:Blogger.