2019互動技術
2019.11.21
1.Makeruno
安裝驅動程式
寫出兩行簡單的程式碼
運用老師給的網址撰寫程式碼
使用for迴圈讓電路板亮不同的燈
void setup() {
// put your setup code here, to run once:
pinMode(2,INPUT_PULLUP);
for(int i=2;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);
}
}
撰寫音樂程式碼(小蜜蜂)
可以按鍵盤上的數字鍵
會發出Do Ra Mi Fa So
#define NOTE_C5 523
#define NOTE_D5 587
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_G5 784
void setup() {
// put your setup code here, to run once:
pinMode(8,OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()){
char now = Serial.read();
if(now=='1') tone(8,NOTE_C5,300);
if(now=='2') tone(8,NOTE_D5,300);
if(now=='3') tone(8,NOTE_E5,300);
if(now=='4') tone(8,NOTE_F5,300);
if(now=='5') tone(8,NOTE_G5,300);
}
}
////////////////////////////////////////////////////////////
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');
}














沒有留言:
張貼留言