透過 Processing 讓 Arduino 位於 pin 13 上面的 LED 閃爍。
原文詳 http://playground.arduino.cc/Interfacing/Processing
Arduino Code
請開啟並上載 File > Examples > Firmata > StandardFirmata.ino
Processing Code
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int ledPin = 13;
void setup()
{
//println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode(ledPin, Arduino.OUTPUT);
}
void draw()
{
arduino.digitalWrite(ledPin, Arduino.HIGH);
delay(1000);
arduino.digitalWrite(ledPin, Arduino.LOW);
delay(1000);
}
2015年2月9日 星期一
靜聽花開的聲音
這是一個 Arduino 與 Processing 互動的實例,改變 Arduino A0 pin 輸出的值就可以讓 Processing 裏的樹狀結構改變形狀。
原文詳 http://playground.arduino.cc/Interfacing/ProcesssHackForFirmata
Arduino Code
請開啟並上載 File > Examples > Firmata > StandardFirmata.ino
Processing Code
/*
* Recursive Tree
* by Daniel Shiffman
*
* Renders a simple tree-like structure via recursion
* Branching angle calculated as a function of horizontal mouse location
*/
import processing.serial.*; // reference the serial library
import cc.arduino.*; // reference the arduino library
Arduino arduino; // create a variable arduino of the Arduino data type
float theta;
void setup() {
size(200, 200);
smooth();
println(Serial.list()); // List all the available serial ports:
//arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino = new Arduino(this, "COM4", 57600);
}
void draw() {
background(0);
frameRate(30);
stroke(255);
// Let's pick an angle 0 to 90 degrees based on the mouse position
/* float a = (mouseX / (float) width) * 90f; // original line */
float a = (arduino.analogRead(0) / (float) width) * 90f;
// Convert it to radians
theta = radians(a);
// Start the tree from the bottom of the screen
translate(width/2, height);
// Draw a line 60 pixels
line(0, 0, 0, -60);
// Move to the end of that line
translate(0, -60);
// Start the recursive branching!
branch(60);
}
void branch(float h) {
// Each branch will be 2/3rds the size of the previous one
h *= 0.66f;
// All recursive functions must have an exit condition!!!!
// Here, ours is when the length of the branch is 2 pixels or less
if (h > 2) {
pushMatrix(); // Save the current state of transformation (i.e. where are we now)
rotate(theta); // Rotate by theta
line(0, 0, 0, -h); // Draw the branch
translate(0, -h); // Move to the end of the branch
branch(h); // Ok, now call myself to draw two new branches!!
popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
// Repeat the same thing, only branch off to the "left" this time!
pushMatrix();
rotate(-theta);
line(0, 0, 0, -h);
translate(0, -h);
branch(h);
popMatrix();
}
}
建議您
你也可以把 Processing Code 這一行
float a = (arduino.analogRead(0) / (float) width) * 90f;
改成
float a = (mouseX / (float) width) * 90f;
如此,即可不必透過讀取 Arduino A0 pin 的值,只要左右移動滑鼠就可以改變樹的形狀。
原文詳 http://playground.arduino.cc/Interfacing/ProcesssHackForFirmata
Arduino Code
請開啟並上載 File > Examples > Firmata > StandardFirmata.ino
Processing Code
/*
* Recursive Tree
* by Daniel Shiffman
*
* Renders a simple tree-like structure via recursion
* Branching angle calculated as a function of horizontal mouse location
*/
import processing.serial.*; // reference the serial library
import cc.arduino.*; // reference the arduino library
Arduino arduino; // create a variable arduino of the Arduino data type
float theta;
void setup() {
size(200, 200);
smooth();
println(Serial.list()); // List all the available serial ports:
//arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino = new Arduino(this, "COM4", 57600);
}
void draw() {
background(0);
frameRate(30);
stroke(255);
// Let's pick an angle 0 to 90 degrees based on the mouse position
/* float a = (mouseX / (float) width) * 90f; // original line */
float a = (arduino.analogRead(0) / (float) width) * 90f;
// Convert it to radians
theta = radians(a);
// Start the tree from the bottom of the screen
translate(width/2, height);
// Draw a line 60 pixels
line(0, 0, 0, -60);
// Move to the end of that line
translate(0, -60);
// Start the recursive branching!
branch(60);
}
void branch(float h) {
// Each branch will be 2/3rds the size of the previous one
h *= 0.66f;
// All recursive functions must have an exit condition!!!!
// Here, ours is when the length of the branch is 2 pixels or less
if (h > 2) {
pushMatrix(); // Save the current state of transformation (i.e. where are we now)
rotate(theta); // Rotate by theta
line(0, 0, 0, -h); // Draw the branch
translate(0, -h); // Move to the end of the branch
branch(h); // Ok, now call myself to draw two new branches!!
popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
// Repeat the same thing, only branch off to the "left" this time!
pushMatrix();
rotate(-theta);
line(0, 0, 0, -h);
translate(0, -h);
branch(h);
popMatrix();
}
}
建議您
你也可以把 Processing Code 這一行
float a = (arduino.analogRead(0) / (float) width) * 90f;
改成
float a = (mouseX / (float) width) * 90f;
如此,即可不必透過讀取 Arduino A0 pin 的值,只要左右移動滑鼠就可以改變樹的形狀。
2015年2月1日 星期日
踏出互動的第一步 - 串行呼叫與回應
對話是溝通的開始,你講你的英文我講我的拉丁文,牛頭不對馬嘴這樣是不行的。
除了你講的我能懂,我講的你也能懂之外,還要建立起彼此間說話的規則,否則你一句我也來一句,這樣有講等於沒講。
另外一點是,兩個人說話總有一方先起頭,另一方才隨後附和,所以就變成有主從關係。通常主方會持續發出「我想和你說話,你知道了嗎?如果知道了,那麼我可以開始說了嗎?」類似這樣的訊息,而從方則會持續發出「你是在跟我說話嗎?如果是的話那麼你可以開始說了。」類似這樣的訊息。
想要讓 Arduino 和 Processing 這兩個軟體彼此有良好的溝通,也必須透過上述所講的方式進行。
本文示範讓 Arduino 和 電腦端的 Processing 互傳多字節資料。一開始 Arduino 會先持續傳送一個 ASCII 碼 'A' 給 Processing,直到 Processing 有了回應,Arduino 才會繼續後續的動作。
你可以利用連接在 Arduino 上面的兩個電位器移動電腦上的小白點,也可以按下按鈕讓小白點消失或是出現。
原文 http://arduino.cc/en/Tutorial/SerialCallResponse
電路圖
Arduino Code
/*
Serial Call and Response
Language: Wiring/Arduino
This program sends an ASCII A (byte of value 65) on startup
and repeats that until it gets some data in.
Then it waits for a byte in the serial port, and
sends three sensor values whenever it gets a byte in.
Thanks to Greg Shakar and Scott Fitzgerald for the improvements
The circuit:
* potentiometers attached to analog inputs 0 and 1
* pushbutton attached to digital I/O 2
Created 26 Sept. 2005
by Tom Igoe
modified 24 April 2012
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/SerialCallResponse
*/
int firstSensor = 0; // first analog sensor
int secondSensor = 0; // second analog sensor
int thirdSensor = 0; // digital sensor
int inByte = 0; // incoming serial byte
void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(2, INPUT); // digital sensor is on digital pin 2
establishContact(); // send a byte to establish contact until receiver responds
}
void loop()
{
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
// read first analog input, divide by 4 to make the range 0-255:
firstSensor = analogRead(A0)/4;
// delay 10ms to let the ADC recover:
delay(10);
// read second analog input, divide by 4 to make the range 0-255:
secondSensor = analogRead(1)/4;
// read switch, map it to 0 or 255L
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
// send sensor values:
Serial.write(firstSensor);
Serial.write(secondSensor);
Serial.write(thirdSensor);
}
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.print('A'); // send a capital A
delay(300);
}
}
Processing Code
// This example code is in the public domain.
import processing.serial.*;
int bgcolor; // Background color
int fgcolor; // Fill color
Serial myPort; // The serial port
int[] serialInArray = new int[3]; // Where we'll put what we receive
int serialCount = 0; // A count of how many bytes we receive
int xpos, ypos; // Starting position of the ball
boolean firstContact = false; // Whether we've heard from the microcontroller
void setup() {
size(256, 256); // Stage size
noStroke(); // No border on the next thing drawn
// Set the starting position of the ball (middle of the stage)
xpos = width/2;
ypos = height/2;
// Print a list of the serial ports, for debugging purposes:
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw() {
background(bgcolor);
fill(fgcolor);
// Draw the shape
ellipse(xpos, ypos, 20, 20);
}
void serialEvent(Serial myPort) {
// read a byte from the serial port:
int inByte = myPort.read();
// if this is the first byte received, and it's an A,
// clear the serial buffer and note that you've
// had first contact from the microcontroller.
// Otherwise, add the incoming byte to the array:
if (firstContact == false) {
if (inByte == 'A') {
myPort.clear(); // clear the serial port buffer
firstContact = true; // you've had first contact from the microcontroller
myPort.write('A'); // ask for more
}
}
else {
// Add the latest byte from the serial port to array:
serialInArray[serialCount] = inByte;
serialCount++;
// If we have 3 bytes:
if (serialCount > 2 ) {
xpos = serialInArray[0];
ypos = serialInArray[1];
fgcolor = serialInArray[2];
// print the values (for debugging purposes only):
println(xpos + "\t" + ypos + "\t" + fgcolor);
// Send a capital A to request new sensor readings:
myPort.write('A');
// Reset serialCount:
serialCount = 0;
}
}
}
除了你講的我能懂,我講的你也能懂之外,還要建立起彼此間說話的規則,否則你一句我也來一句,這樣有講等於沒講。
另外一點是,兩個人說話總有一方先起頭,另一方才隨後附和,所以就變成有主從關係。通常主方會持續發出「我想和你說話,你知道了嗎?如果知道了,那麼我可以開始說了嗎?」類似這樣的訊息,而從方則會持續發出「你是在跟我說話嗎?如果是的話那麼你可以開始說了。」類似這樣的訊息。
想要讓 Arduino 和 Processing 這兩個軟體彼此有良好的溝通,也必須透過上述所講的方式進行。
本文示範讓 Arduino 和 電腦端的 Processing 互傳多字節資料。一開始 Arduino 會先持續傳送一個 ASCII 碼 'A' 給 Processing,直到 Processing 有了回應,Arduino 才會繼續後續的動作。
你可以利用連接在 Arduino 上面的兩個電位器移動電腦上的小白點,也可以按下按鈕讓小白點消失或是出現。
原文 http://arduino.cc/en/Tutorial/SerialCallResponse
電路圖
Arduino Code
/*
Serial Call and Response
Language: Wiring/Arduino
This program sends an ASCII A (byte of value 65) on startup
and repeats that until it gets some data in.
Then it waits for a byte in the serial port, and
sends three sensor values whenever it gets a byte in.
Thanks to Greg Shakar and Scott Fitzgerald for the improvements
The circuit:
* potentiometers attached to analog inputs 0 and 1
* pushbutton attached to digital I/O 2
Created 26 Sept. 2005
by Tom Igoe
modified 24 April 2012
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/SerialCallResponse
*/
int firstSensor = 0; // first analog sensor
int secondSensor = 0; // second analog sensor
int thirdSensor = 0; // digital sensor
int inByte = 0; // incoming serial byte
void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(2, INPUT); // digital sensor is on digital pin 2
establishContact(); // send a byte to establish contact until receiver responds
}
void loop()
{
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
// read first analog input, divide by 4 to make the range 0-255:
firstSensor = analogRead(A0)/4;
// delay 10ms to let the ADC recover:
delay(10);
// read second analog input, divide by 4 to make the range 0-255:
secondSensor = analogRead(1)/4;
// read switch, map it to 0 or 255L
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
// send sensor values:
Serial.write(firstSensor);
Serial.write(secondSensor);
Serial.write(thirdSensor);
}
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.print('A'); // send a capital A
delay(300);
}
}
Processing Code
// This example code is in the public domain.
import processing.serial.*;
int bgcolor; // Background color
int fgcolor; // Fill color
Serial myPort; // The serial port
int[] serialInArray = new int[3]; // Where we'll put what we receive
int serialCount = 0; // A count of how many bytes we receive
int xpos, ypos; // Starting position of the ball
boolean firstContact = false; // Whether we've heard from the microcontroller
void setup() {
size(256, 256); // Stage size
noStroke(); // No border on the next thing drawn
// Set the starting position of the ball (middle of the stage)
xpos = width/2;
ypos = height/2;
// Print a list of the serial ports, for debugging purposes:
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw() {
background(bgcolor);
fill(fgcolor);
// Draw the shape
ellipse(xpos, ypos, 20, 20);
}
void serialEvent(Serial myPort) {
// read a byte from the serial port:
int inByte = myPort.read();
// if this is the first byte received, and it's an A,
// clear the serial buffer and note that you've
// had first contact from the microcontroller.
// Otherwise, add the incoming byte to the array:
if (firstContact == false) {
if (inByte == 'A') {
myPort.clear(); // clear the serial port buffer
firstContact = true; // you've had first contact from the microcontroller
myPort.write('A'); // ask for more
}
}
else {
// Add the latest byte from the serial port to array:
serialInArray[serialCount] = inByte;
serialCount++;
// If we have 3 bytes:
if (serialCount > 2 ) {
xpos = serialInArray[0];
ypos = serialInArray[1];
fgcolor = serialInArray[2];
// print the values (for debugging purposes only):
println(xpos + "\t" + ypos + "\t" + fgcolor);
// Send a capital A to request new sensor readings:
myPort.write('A');
// Reset serialCount:
serialCount = 0;
}
}
}
2015年1月28日 星期三
移動滑鼠開/關 LED
移動滑鼠到畫面中的小方塊裏面,就會點亮 LED,移開滑鼠 LED 會跟著變暗。
原文詳 http://arduino.cc/en/Tutorial/PhysicalPixel
電路圖
Arduino Code
/*
Physical Pixel
An example of using the Arduino board to receive data from the
computer. In this case, the Arduino boards turns on an LED when
it receives the character 'H', and turns off the LED when it
receives the character 'L'.
The data can be sent from the Arduino serial monitor, or another
program like Processing (see code below), Flash (via a serial-net
proxy), PD, or Max/MSP.
The circuit:
* LED connected from digital pin 13 to ground
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/PhysicalPixel
*/
const int ledPin = 13; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
}
}
}
Processing Code
// mouseover serial
// Demonstrates how to send data to the Arduino I/O board, in order to
// turn ON a light if the mouse is over a square and turn it off
// if the mouse is not.
// created 2003-4
// based on examples by Casey Reas and Hernando Barragan
// modified 30 Aug 2011
// by Tom Igoe
// This example code is in the public domain.
import processing.serial.*;
float boxX;
float boxY;
int boxSize = 20;
boolean mouseOverBox = false;
Serial port;
void setup() {
size(200, 200);
boxX = width/2.0;
boxY = height/2.0;
rectMode(RADIUS);
// List all the available serial ports in the output pane.
// You will need to choose the port that the Arduino board is
// connected to from this list. The first port in the list is
// port #0 and the third port in the list is port #2.
println(Serial.list());
// Open the port that the Arduino board is connected to (in this case #0)
// Make sure to open the port at the same speed Arduino is using (9600bps)
port = new Serial(this, "COM5", 9600);
}
void draw()
{
background(0);
// Test if the cursor is over the box
if (mouseX > boxX-boxSize && mouseX < boxX+boxSize &&
mouseY > boxY-boxSize && mouseY < boxY+boxSize) {
mouseOverBox = true;
// draw a line around the box and change its color:
stroke(255);
fill(153);
// send an 'H' to indicate mouse is over square:
port.write('H');
}
else {
// return the box to it's inactive state:
stroke(153);
fill(153);
// send an 'L' to turn the LED off:
port.write('L');
mouseOverBox = false;
}
// Draw the box
rect(boxX, boxY, boxSize, boxSize);
}
提醒您
1. 雖然電路圖的 LED 是插在 pin 13,但因為 Arduino 板子上面的 pin 13 已經內建一只 LED,所以您也可以不必插入任何 LED,只要觀察 Arduino 板子上面的 LED 即可。
2. 檢查 COM 埠有沒有正確。
3. 檢查 鮑率 是不是 9600。
原文詳 http://arduino.cc/en/Tutorial/PhysicalPixel
電路圖
Arduino Code
/*
Physical Pixel
An example of using the Arduino board to receive data from the
computer. In this case, the Arduino boards turns on an LED when
it receives the character 'H', and turns off the LED when it
receives the character 'L'.
The data can be sent from the Arduino serial monitor, or another
program like Processing (see code below), Flash (via a serial-net
proxy), PD, or Max/MSP.
The circuit:
* LED connected from digital pin 13 to ground
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/PhysicalPixel
*/
const int ledPin = 13; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
}
}
}
Processing Code
// mouseover serial
// Demonstrates how to send data to the Arduino I/O board, in order to
// turn ON a light if the mouse is over a square and turn it off
// if the mouse is not.
// created 2003-4
// based on examples by Casey Reas and Hernando Barragan
// modified 30 Aug 2011
// by Tom Igoe
// This example code is in the public domain.
import processing.serial.*;
float boxX;
float boxY;
int boxSize = 20;
boolean mouseOverBox = false;
Serial port;
void setup() {
size(200, 200);
boxX = width/2.0;
boxY = height/2.0;
rectMode(RADIUS);
// List all the available serial ports in the output pane.
// You will need to choose the port that the Arduino board is
// connected to from this list. The first port in the list is
// port #0 and the third port in the list is port #2.
println(Serial.list());
// Open the port that the Arduino board is connected to (in this case #0)
// Make sure to open the port at the same speed Arduino is using (9600bps)
port = new Serial(this, "COM5", 9600);
}
void draw()
{
background(0);
// Test if the cursor is over the box
if (mouseX > boxX-boxSize && mouseX < boxX+boxSize &&
mouseY > boxY-boxSize && mouseY < boxY+boxSize) {
mouseOverBox = true;
// draw a line around the box and change its color:
stroke(255);
fill(153);
// send an 'H' to indicate mouse is over square:
port.write('H');
}
else {
// return the box to it's inactive state:
stroke(153);
fill(153);
// send an 'L' to turn the LED off:
port.write('L');
mouseOverBox = false;
}
// Draw the box
rect(boxX, boxY, boxSize, boxSize);
}
提醒您
1. 雖然電路圖的 LED 是插在 pin 13,但因為 Arduino 板子上面的 pin 13 已經內建一只 LED,所以您也可以不必插入任何 LED,只要觀察 Arduino 板子上面的 LED 即可。
2. 檢查 COM 埠有沒有正確。
3. 檢查 鮑率 是不是 9600。
移動滑鼠控制 LED 明暗
您可以透過左右移動滑鼠來控制 LED 的明暗,往右變亮,往左變暗。
原文詳 http://arduino.cc/en/Tutorial/Dimmer
電路圖
Arduino Code
const int ledPin = 9; // the pin that the LED is attached to
void setup()
{
// initialize the serial communication:
Serial.begin(9600);
// initialize the ledPin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
byte brightness;
// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
brightness = Serial.read();
// set the brightness of the LED:
analogWrite(ledPin, brightness);
}
}
Processing Code
// Dimmer - sends bytes over a serial port
// by David A. Mellis
//This example code is in the public domain.
import processing.serial.*;
Serial port;
void setup() {
size(256, 150);
println("Available serial ports:");
println(Serial.list());
// Uses the first port in this list (number 0). Change this to
// select the port corresponding to your Arduino board. The last
// parameter (e.g. 9600) is the speed of the communication. It
// has to correspond to the value passed to Serial.begin() in your
// Arduino sketch.
port = new Serial(this, "COM5", 9600);
// If you know the name of the port used by the Arduino board, you
// can specify it directly like this.
//port = new Serial(this, "COM1", 9600);
}
void draw() {
// draw a gradient from black to white
for (int i = 0; i < 256; i++) {
stroke(i);
line(i, 0, i, 150);
}
// write the current X-position of the mouse to the serial port as
// a single byte
port.write(mouseX);
}
原文詳 http://arduino.cc/en/Tutorial/Dimmer
電路圖
Arduino Code
const int ledPin = 9; // the pin that the LED is attached to
void setup()
{
// initialize the serial communication:
Serial.begin(9600);
// initialize the ledPin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
byte brightness;
// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
brightness = Serial.read();
// set the brightness of the LED:
analogWrite(ledPin, brightness);
}
}
Processing Code
// Dimmer - sends bytes over a serial port
// by David A. Mellis
//This example code is in the public domain.
import processing.serial.*;
Serial port;
void setup() {
size(256, 150);
println("Available serial ports:");
println(Serial.list());
// Uses the first port in this list (number 0). Change this to
// select the port corresponding to your Arduino board. The last
// parameter (e.g. 9600) is the speed of the communication. It
// has to correspond to the value passed to Serial.begin() in your
// Arduino sketch.
port = new Serial(this, "COM5", 9600);
// If you know the name of the port used by the Arduino board, you
// can specify it directly like this.
//port = new Serial(this, "COM1", 9600);
}
void draw() {
// draw a gradient from black to white
for (int i = 0; i < 256; i++) {
stroke(i);
line(i, 0, i, 150);
}
// write the current X-position of the mouse to the serial port as
// a single byte
port.write(mouseX);
}
提醒您
1. LED 要插在 pin 9,或是其它 PWM 埠。
2. 檢查 COM 埠有沒有正確。
3. 檢查 鮑率 是不是 9600。
建議
您也可以修改程式碼,把它改成可以控制舵機角度。
1. LED 要插在 pin 9,或是其它 PWM 埠。
2. 檢查 COM 埠有沒有正確。
3. 檢查 鮑率 是不是 9600。
建議
您也可以修改程式碼,把它改成可以控制舵機角度。
2015年1月25日 星期日
照片轉 3D
2D 轉 3D 大體上有兩種方式,一種是沿著 Z 軸擠出高度;另一種是透過許多的 2D 圖片資料,利用數學運算的方式算出物體在空間中的座標,而後建立出 3D 模型。
用一張照片擠出為 3D 模型
Cura 3D 列印軟體可以讀入 JPG 等點陣圖,然後將它另存為 STL 檔。之後可以用 SketchUp 或 ThinkerCAD 編輯它。
Cura 官網與下載 https://ultimaker.com/en/products/software
SketchUp 詳 http://pizgchen.blogspot.tw/2014/06/stl.html
ThinkerCAD 詳 http://pizgchen.blogspot.tw/2015/01/thinkercad.html
用許多照片轉換為 3D 模型
AutoDesk 的 123D Catch 軟體可以幫您把照片轉成 3D 模型。
官網 http://www.123dapp.com/catch
應用詳 http://iphone4.tw/forums/showthread.php?t=210261
用一張照片擠出為 3D 模型
Cura 3D 列印軟體可以讀入 JPG 等點陣圖,然後將它另存為 STL 檔。之後可以用 SketchUp 或 ThinkerCAD 編輯它。
Cura 官網與下載 https://ultimaker.com/en/products/software
SketchUp 詳 http://pizgchen.blogspot.tw/2014/06/stl.html
ThinkerCAD 詳 http://pizgchen.blogspot.tw/2015/01/thinkercad.html
用許多照片轉換為 3D 模型
AutoDesk 的 123D Catch 軟體可以幫您把照片轉成 3D 模型。
官網 http://www.123dapp.com/catch
應用詳 http://iphone4.tw/forums/showthread.php?t=210261
ThinkerCAD 下載、安裝與設定
ThinkerCAD 是 AutoDesk 公司開發的一款線上繪圖軟體,您可以用它編輯 STL 檔,也可以匯入 SVG 檔,將兩者結合在一起,成為一個新的 3D 模型。
官網 https://www.tinkercad.com/
下載
ThinkerCAD 是線上繪圖軟體,無須下載,但使用前要先註冊。
註冊
1. 填寫您「所在地區」與「生日」。點擊「下一步」。
2. 您可以用您的 Facebook 帳號註冊,也可以在下方填寫您的「電子郵件地址」與「登入密碼」。點擊「建立帳戶」。
基本操作 http://www.minwt.com/free/9511.html
應用操作 http://inplus.tw/archives/368
官網 https://www.tinkercad.com/
下載
ThinkerCAD 是線上繪圖軟體,無須下載,但使用前要先註冊。
註冊
1. 填寫您「所在地區」與「生日」。點擊「下一步」。
2. 您可以用您的 Facebook 帳號註冊,也可以在下方填寫您的「電子郵件地址」與「登入密碼」。點擊「建立帳戶」。
基本操作 http://www.minwt.com/free/9511.html
應用操作 http://inplus.tw/archives/368
訂閱:
文章 (Atom)







