2019年11月21日 星期四

Week_11

pinMode(13,OUTPUT);
digitalWrite(13,HIGH);



#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;
}
}

void setup() {
  // put your setup code here, to run once:
   pinMode(2,INPUT_PULLUP);
  for(int i=3;i<=13;i++){
    pinMode(i,OUTPUT);
    //digitalWrite(i,HIGH);
  }
}

bool bLightHIGH=true;
void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(2)==HIGH) bLightHIGH=true;
  else bLightHIGH=false;

  for(int i=3;i<=13;i++){
      if(bLightHIGH) digitalWrite(i,HIGH);
      else digitalWrite(i,LOW);
    }
}



P語言import processing.serial.*;
Serial myPort;

void setup(){
  myPort = new Serial(this,"COM4",9600);
}
void draw(){

}

void keyPressed(){
  if(key=='1') myPort.write('1');
  if(key=='2') myPort.write('2');
  if(key=='3') myPort.write('3');
  if(key=='4') myPort.write('4');
  if(key=='5') myPort.write('5');
}

沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

回顧這學期的作品:  期中作業:LANDING:PLANET 賣點&特點: 炫麗的特效 物理(星球重力及降落)及粒子系統(噴射) 世界地圖可根據視角縮放 困難點: 重寫3次最終改寫成物件導向的CLASS寫法...