首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >处理/节律记录

处理/节律记录
EN

Stack Overflow用户
提问于 2015-04-22 21:47:51
回答 1查看 47关注 0票数 0

我在做一个学生项目。我正试着录制一首有节奏的曲子,并在此基础上画出垂直线的网格。它看起来就像是撞翻了一个木箱(arduino;标准的firmata)。然后,处理需要映射此记录的时间和屏幕的宽度-并在敲击位置绘制垂直线。

请帮帮忙,这次要在哪里录音,然后把它映射到屏幕上。

到目前为止,我已经有了这个代码。但它只在有屏幕空间时在敲门上绘制线条;并以pdf格式保存。

代码语言:javascript
运行
复制
 import processing.serial.*;
 import cc.arduino.*;
 import processing.pdf.*;

 Arduino arduino;

 Serial myPort;       

 int x = 0;

 void setup() {
     size(500, 500);
     background(#ffffff);

     println(Arduino.list());

     arduino = new Arduino(this, "/dev/tty.usbmodem1411", 57600);

     //Set the Arduino digital pins as inputs.
     arduino.pinMode(0, Arduino.INPUT);

     beginRecord(PDF, "everything.pdf");
 }
 void draw() {
     stroke(0);

     for (int i = 0; i <= 0; i++) {
         if (arduino.analogRead(i)>0) {
             line(x, 0, x, height);
         }
         else {
              x +=1;
         }
     }
 }
 void keyPressed() {
     endRecord();
     codexit();
 } 
EN

回答 1

Stack Overflow用户

发布于 2015-05-04 02:28:22

我终于完成了这件事。假设它可以做得更好,范围更广,但事实是它是有效的。

关于结果的小视频:https://www.dropbox.com/s/1dp5tqqx16zp4l7/Abramova-5FCC0022-video.mov?dl=0

和代码:

代码语言:javascript
运行
复制
import processing.serial.*;
import cc.arduino.*;

Arduino arduino;
PrintWriter output;

// The serial port:
Serial myPort;       

int t = millis();
int[] time;

void setup() {
size(500, 500);
background(#ffffff);

// Prints out the available serial ports.
println(Arduino.list());


// Modify this line, by changing the "0" to the index of the serial
// port corresponding to your Arduino board (as it appears in the list
// printed by the line above).
arduino = new Arduino(this, "/dev/tty.usbmodem1411", 57600);

// Alternatively, use the name of the serial port corresponding to your
// Arduino (in double-quotes), as in the following line.
//arduino = new Arduino(this, "/dev/tty.usbmodem621", 57600);

// Set the Arduino digital pins as inputs.
arduino.pinMode(0, Arduino.INPUT);

// Creates the output for the time, dedicated to the beats.
output = createWriter("time.txt"); 

}

void draw() {

// when arduino sends signal, store the current
// time in milliseconds since the program started

if (arduino.analogRead(0)>30) {

// grabs the time, passed before the beat from start

String numbers = "millis()";
delay(100);
output.print (millis() + ",");

}
}

void keyPressed() {
output.flush();  // Writes the remaining data to the file
output.close();  // Finishes the file

}

void keyReleased() {

// Interprets the string from the saved beat sequence
String[] numbers = loadStrings("time.txt");
time = int(split(numbers[0],','));

stroke(0);
strokeWeight(5);

// Draws lines, based on a string

for (int i = 1;  i < time.length; i++) {
int c = time[i]-time[0];
int d = time[time.length - 2];
int e = time[0];
int f = d-e;

// Vertical lines
line(c*500/f, 0 , c*500/f , height);

// Horisontal lines
line(0, c*500/f, width, c*500/f);

// Drawing rects

// Yellow
fill (255, 255, 0);
int m = (time [1] - time [0])*500/f;
int n = (time [2] - time [0])*500/f;
rect (m, m, n-m, n-m);

// Blue
fill (0, 0, 255);
int o = (time [8] - time [0])*500/f;
int p = (time [4] - time [0])*500/f;
rect (o, m, p-o, p-o);

// Red
fill(255, 0, 0);
int v = (time [3] - time [0])*500/f;
int k = (time [6] - time [0])*500/f;
int z = (time [8] - time [0])*500/f;
rect(v, p, z-v, k-v);

}

} 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29799605

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档