Created
December 11, 2013 17:13
-
-
Save miettal/7914513 to your computer and use it in GitHub Desktop.
発車スイッチを押す車掌さんの気持ちが少しわかるシミュレータ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.video.*; | |
import ddf.minim.spi.*; | |
import ddf.minim.signals.*; | |
import ddf.minim.*; | |
import ddf.minim.analysis.*; | |
import ddf.minim.ugens.*; | |
import ddf.minim.effects.*; | |
import processing.serial.*; | |
Movie movie; | |
Minim minim; | |
AudioPlayer player; | |
Serial port; | |
int old_state = '1'; | |
void setup(){ | |
size(displayWidth, displayHeight-50, P2D); | |
movie = new Movie(this, "hassya.mp4"); | |
movie.frameRate(10); | |
minim = new Minim(this); | |
player = minim.loadFile("64-30-232447207_S64.mp3"); | |
player.setGain(-10.0); | |
println(Serial.list()); | |
String arduinoPort = Serial.list()[5]; | |
port = new Serial(this, arduinoPort, 2400); | |
} | |
void draw(){ | |
if(port.available() > 0){ | |
int state = port.read(); | |
while(port.available() > 0){ | |
state = port.read(); | |
} | |
if(state == old_state){ | |
return; | |
} | |
if(state == '1' && old_state == '0'){ | |
println("Stop!"); | |
movie.play(); | |
player.pause(); | |
}else if(state == '0' && old_state == '1'){ | |
println("Start!"); | |
movie.stop(); | |
movie.play(); | |
movie.jump(1.16); | |
while(!movie.available()); | |
movie.pause(); | |
player.loop(); | |
} | |
old_state = state; | |
} | |
if(movie.available()){ | |
movie.read(); | |
image(movie, 0, 0, width, height); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() | |
{ | |
pinMode(2, INPUT_PULLUP); | |
Serial.begin(2400); | |
} | |
void loop() | |
{ | |
Serial.print(digitalRead(2)); | |
delay(50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment