week 12互動技術
2019_11_28
------------------------------------------------------------------------
🔺 MakerUNO
- 先到老師的公開雲端下載驅動程式
- 照著老師的步驟\作
- 先到老師的公開雲端下載驅動程式
- 照著老師的步驟\作
⧭按了有聲音(Do)
int Do=523;
int Re=587;
int Mi=659;
void setup() {
// put your setup code here, to run once:
pinMode(8,OUTPUT);
digitalWrite(2,INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(2)==LOW)tone(8,Do,1000);
else noTone(8);
}
⧭按了有聲音(會有小蜜蜂so mi mi fa re re.......)
int Do=523;
int Re=587;
int Mi=659;
int Fa=689;
int So=784;
int song[13]={So,Mi,Mi,Fa,Re,Re,Do,Re,Mi,Fa,So,So,So};
int now=0;
bool UP=true;
void setup() {
// put your setup code here, to run once:
pinMode(8,OUTPUT);
digitalWrite(2,INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(2)==LOW){
tone(8,song[now],200);
UP=false;
now =(now+1)%13; ///避免陣列song[now] 超過而當掉
}
else UP=true;
delay(300);
}
沒有留言:
張貼留言