Taking this recitation as a chance to test our sensor for final project, I chose the air pump to be connected with arduino to send values to processing. I tried to have the pump control the speed of the playing video, which is, mapping the values received from the air sensor into the playing speed of the video. So it seems the user is pumping air into the balloon in the video. Later, I also did some test on connecting the lens duster with the same sensor to see if it can be powerful enough to send values. It was a little hard to do that –since the connection is not fixed, I have to use one hand to fix the joint and the other to squeeze the duster. It worked anyway, although not as powerful as the bike pump.
IMG_1605.( this is the video of pumping air to balloon cars)
import processing.serial.*; import osteele.processing.SerialRecord.*; Serial serialPort; SerialRecord serialRecord; import processing.video.*; Movie myMovie; void setup() { background(0); size(852, 480); myMovie = new Movie(this, "Jing'an.mp4"); myMovie.loop(); String serialPortName = SerialUtils.findArduinoPort(); serialPort = new Serial(this, serialPortName, 9600); serialRecord = new SerialRecord(this, serialPort, 1); } void movieEvent(Movie myMovie) { myMovie.read(); } void draw() { serialRecord.read(); int value = serialRecord.get(); float x = map(value, 0, 1024, 0, height); image(myMovie, 0, 0,852, 480); float newSpeed = map(x, 0, 20, 0.1, 8); myMovie.speed(newSpeed); }
#include "SerialRecord.h" SerialRecord writer(1); volatile int pulses; void setup() { Serial.begin(9600); pinMode(2, INPUT); attachInterrupt(digitalPinToInterrupt(2), count_pulses, RISING); } void loop() { pulses = 0; interrupts(); delay(200); noInterrupts(); int value = pulses; writer[0] = value; writer.send(); delay(20); } void count_pulses() { pulses = pulses + 1; }