刚买的flymaple,想使用USB串口通信,但是一直没有成功。现在把程序贴上,希望可以收到高手回复解决。
这是烧录程序。
- int ledPin = 13; // LED connected to digital pin 13
-
- void setup()
- {
- pinMode(ledPin, OUTPUT); // sets the digital pin as output
- }
-
- void loop()
- {
- SerialUSB.print(',');
- SerialUSB.print(',');
- SerialUSB.print('\n');
- digitalWrite(ledPin, HIGH); // sets the LED on
- delay(1000); // waits for a second
- digitalWrite(ledPin, LOW); // sets the LED off
- delay(1000); // waits for a second
-
- }
-
-
-
- 这是processing程序:功能很简单就是看串口是否收到信息然后显示绘图的变化。
- import processing.serial.*;
- Serial myPort;
- final String serialPort = "COM3";
- final int VIEW_SIZE_X=500,VIEW_SIZE_Y = 500;
- PFont font;
- float []Euler = new float[3];
- void setup()
- {
- size(VIEW_SIZE_X,VIEW_SIZE_Y,P3D);
- myPort = new Serial(this,serialPort,115200);
- font = createFont("Courier",32);
- delay(100);
- myPort.clear();
- Euler[0]=0;
- Euler[1]=0;
- Euler[2]=0;
- }
- void draw()
- {
- background(#000000);
- fill(#ffffff);
- if (myPort.available() != 0) {
- Euler[0]+=1;
- Euler[1]+=1;
- Euler[2]+=1;
- delay(1000);
-
- }
- drawCube();
- }
-
-
- void drawCube() {
- pushMatrix();
- translate(VIEW_SIZE_X/2, VIEW_SIZE_Y/2 + 50, 0);
- scale(5, 5, 5);
-
- // a demonstration of the following is at
- // <a href="http://www.varesano.net/blog/fabio/ahrs-sensor-fusion-orientation-filter-3d-graphical-rotating-cube" target="_blank">http://www.varesano.net/blog/fab ... hical-rotating-cube</a>
- rotateZ(-Euler[2]);
- rotateX(-Euler[1]);
- rotateY(-Euler[0]);
-
- buildBoxShape();
-
- popMatrix();
- }
-
-
- void buildBoxShape() {
- //box(60, 10, 40);
- noStroke();
- beginShape(QUADS);
-
- //Z+ (to the drawing area)
- fill(#00ff00);
- vertex(-30, -5, 20);
- vertex(30, -5, 20);
- vertex(30, 5, 20);
- vertex(-30, 5, 20);
-
- //Z-
- fill(#0000ff);
- vertex(-30, -5, -20);
- vertex(30, -5, -20);
- vertex(30, 5, -20);
- vertex(-30, 5, -20);
-
- //X-
- fill(#ff0000);
- vertex(-30, -5, -20);
- vertex(-30, -5, 20);
- vertex(-30, 5, 20);
- vertex(-30, 5, -20);
-
- //X+
- fill(#ffff00);
- vertex(30, -5, -20);
- vertex(30, -5, 20);
- vertex(30, 5, 20);
- vertex(30, 5, -20);
-
- //Y-
- fill(#ff00ff);
- vertex(-30, -5, -20);
- vertex(30, -5, -20);
- vertex(30, -5, 20);
- vertex(-30, -5, 20);
-
- //Y+
- fill(#00ffff);
- vertex(-30, 5, -20);
- vertex(30, 5, -20);
- vertex(30, 5, 20);
- vertex(-30, 5, 20);
-
- endShape();
- }
-
复制代码
硬件串口情况
如图
|