void setup() { arduino = new Arduino(this, Arduino.list()[1], 57600);
size(500, 500); minim = new Minim( this ); out = minim.getLineOut();
// make the Oscil we will hear. // arguments are frequency, amplitude, and waveform Oscil wave = new Oscil( 200, 0.8, Waves.TRIANGLE ); // make the Oscil we will use to modulate the frequency of wave. // the frequency of this Oscil will determine how quickly the // frequency of wave changes and the amplitude determines how much. // since we are using the output of fm directly to set the frequency // of wave, you can think of the amplitude as being expressed in Hz. fm = new Oscil( 10, 2, Waves.SINE ); // set the offset of fm so that it generates values centered around 200 Hz fm.offset.setLastValue( 200 ); // patch it to the frequency of wave so it controls it fm.patch( wave.frequency ); // and patch wave to the output wave.patch( out );
// draw using a white stroke stroke( 255 ); // draw the waveforms for( int i = 0; i < out.bufferSize() - 1; i++ ) { // find the x position of each buffer value float x1 = map( i, 0, out.bufferSize(), 0, width ); float x2 = map( i+1, 0, out.bufferSize(), 0, width ); // draw a line from one buffer position to the next for both channels line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50); line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50); }
-----03Analog/ AnalogInOutSerial
回覆刪除processing: SimpleRead
https://github.com/pardo-bsso/processing-arduino
http://goo.gl/TEf8L
網址大小寫有差異
=> arduino: 上傳 Firmata >> SimpleAnalogFirmata
=> Processing => contributionLibrary >> arduino_INPUT 修改COM PORT
//processing範例程式開始
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
void setup()
{
arduino = new Arduino(this, Arduino.list()[1], 57600);
size(500, 500);
}
int input = 255;
void draw() {
background(0);
input = arduino.analogRead(0); // 0~1023
println(arduino.analogRead(0));
rect(0, 0, 100, input);
}
///processing範例程式結束
光敏接線圖: http://fritzing.org/projects/simple-ldr/
回覆刪除// processing minim and arduino---------- 開始
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
import ddf.minim.*;
import ddf.minim.ugens.*;
Minim minim;
AudioOutput out;
Oscil fm;
void setup()
{
arduino = new Arduino(this, Arduino.list()[1], 57600);
size(500, 500);
minim = new Minim( this );
out = minim.getLineOut();
// make the Oscil we will hear.
// arguments are frequency, amplitude, and waveform
Oscil wave = new Oscil( 200, 0.8, Waves.TRIANGLE );
// make the Oscil we will use to modulate the frequency of wave.
// the frequency of this Oscil will determine how quickly the
// frequency of wave changes and the amplitude determines how much.
// since we are using the output of fm directly to set the frequency
// of wave, you can think of the amplitude as being expressed in Hz.
fm = new Oscil( 10, 2, Waves.SINE );
// set the offset of fm so that it generates values centered around 200 Hz
fm.offset.setLastValue( 200 );
// patch it to the frequency of wave so it controls it
fm.patch( wave.frequency );
// and patch wave to the output
wave.patch( out );
}
int input = 255;
void draw() {
background(0);
input = arduino.analogRead(0); // 0~1023
println(arduino.analogRead(0));
rect(0, 0, 100, input);
// draw using a white stroke
stroke( 255 );
// draw the waveforms
for( int i = 0; i < out.bufferSize() - 1; i++ )
{
// find the x position of each buffer value
float x1 = map( i, 0, out.bufferSize(), 0, width );
float x2 = map( i+1, 0, out.bufferSize(), 0, width );
// draw a line from one buffer position to the next for both channels
line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
}
float modulateFrequency = map( input, 0, 55, 0.1, 1000 );
float modulateAmount = map( input, 0, 55, 1000, 1 );
fm.frequency.setLastValue( modulateFrequency );
fm.amplitude.setLastValue( modulateAmount );
}
// ending
next week: http://en.wikipedia.org/wiki/Servomotor
回覆刪除上課前準報好一個 伺服馬達 規格盡量小跟5v以內的電壓 SG90 Tower Pro