2013年4月10日 星期三
Arduino + 可變電阻 + Process
//Arduino 程式
int sensorPin=0;
int val=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
val=analogRead(sensorPin)/4;
Serial.write(val); //老版本会用Serial.print(val,BYTE),现在已经不支持BYTE了。
delay(100);
}
//Process 程式
//String arduinoPort = Serial.list()[1];//如果[0]不行,就换[1]
import processing.serial.*;
Serial port;
float val;
float angle;
float radius;
void setup() {
size(440, 440);
frameRate(30);
strokeWeight(2);
smooth();
String arduinoPort = Serial.list()[1];//如果[0]不行,就换[1]
port = new Serial(this, arduinoPort, 9600);
background(0);
}
void draw() {
if ( port.available()> 0) {
val = port.read();
radius = map(val, 0, 255, 0, height * 0.45);
}
int middleX = width/2;
int middleY = height/2;
float x = middleX + cos(angle) * height/2;
float y = middleY + sin(angle) * height/2;
stroke(0);
line(middleX, middleY, x, y);
x = middleX + cos(angle) * radius;
y = middleY + sin(angle) * radius;
stroke(255);
line(middleX, middleY, x, y);
angle += 0.01;
}
//stroke(255-val,10+val,val);
import processing.serial.*;
Serial port;
float val;
float angle;
float radius;
void setup() {
size(440, 440);
frameRate(30);
strokeWeight(2);
smooth();
String arduinoPort = Serial.list()[1];//如果[0]不行,就换[1]
port = new Serial(this, arduinoPort, 9600);
background(0);
}
void draw() {
if ( port.available()> 0) {
val = port.read();
radius = map(val, 0, 255, 0, height * 0.45);
}
int middleX = width/2;
int middleY = height/2;
float x = middleX + cos(angle) * height/2;
float y = middleY + sin(angle) * height/2;
stroke(0);
line(middleX, middleY, x, y);
x = middleX + cos(angle) * radius;
y = middleY + sin(angle) * radius;
stroke(255-val,10+val,val);
line(middleX, middleY, x, y);
angle += 0.01;
}
訂閱:
張貼留言 (Atom)
Wokwi 的 Analog stick 控制 EasyBuilderPro HMI 的' 移動圖形
Wokwi 的 Analog stick 控制 EasyBuilderPro HMI 的' 移動圖形 const char * mqtt_server = "broker.emqx.io" ; client . publish (...
-
數位IC設計入門-Verilog combinational logic 8 to 1 Multiplexer 多工器 Behavioral Modeling (& Test Bench) //數位IC設計入門-Verilog combinationa...
-
Line 發報機 Python TKinter (CONFIG_LINE Message API_2.py) import serial import serial.tools.list_ports import tkinter as tk from tkinter import...
-
python pip 不是内部或外部命令 -- 解決方法 要安裝 Pyqt5 1. 首先,開啟命令提示字元。 2. 輸入 pip3 install pyqt5 好像不能執行 ! ! 錯誤顯示 : ‘ pip3 ’ 不是內部或外部命令、可執行的程式或批...



沒有留言:
張貼留言