2020年12月21日 星期一

🗿week15


 

圖片

//int a=10

size(600,600);

PImage img=loadImage("img.jpg");

PVector pt=new ector(10 , 20, 0);

image(img ,0 ,0);

println(pt.x);5

//以前要用的時候

float userX=10,userY=20,userZ=0;

float user2X=30,user2Y=40,user2Z=0;

//現在可以用的物件,來讓他有條理

PVector user=new PVector(10,20,0);

PVector user2=new PVector(10,20,0);

_______________________________________________________________________

arduino

void setup() {

  // put your setup code here, to run once:

  pinMode(2,INPUT_PULLUP);

  Serial.begin(9600);

}


void loop() {

  // put your main code here, to run repeatedly:

  int x=analogRead(A0);

  int y=analogRead(A1);

  int sw=digitalRead(2);


  Serial.write(x/4);

  Serial.write(y/4);

  Serial.write(sw);

  delay(20);  

}

processing

PVector user;

PVector Y,v=null;

void setup(){

    size(600,600);

    user = new PVector(100,300.);

    Y=new PVector(100,300);

}

void draw(){

  background(255);

  line(user.x,user.y,Y.x,Y.y);

  textSize(40);

  fill(255,0,0); text("Y",Y.x,Y.y);

  fill(255); ellipse(user.x, user.y,20,20);

  if(v!=null) user.add(v);

}

void mouseReleased(){

  PVector diff = PVector.sub(Y,user);

  v = diff.div(10);

}___________________________________________________



processing

import processing.serial.*;

Serial myPort;

void setup(){

size(256,256);

myPort = new Serial(this, "COM6",9600);

}

int bal1X=0,bal1Y=0;

void draw()

{

 if(myPort.available()>=3)

 {

   int x = myPort.read();

   int y = myPort.read();

   int sw = myPort.read();

   bal1X=x;

   bal1Y=y;

 }

 ellipse(bal1X,bal1Y,10,10);

}


Arduino程式碼

void setup()

{

  pinMode(2, INPUT_PULLUP);//拉高的Input

  Serial.begin(9600);//開始設定USB的傳輸速度

}

void loop() {//1000Hz (1000 fps)

  int x = analogRead(A0);//0...1023

  int y = analogRead(A1);//0...1023

  int sw= digitalRead(2);//HIGH(放開)

  

  Serial.write (x/4);//第1個byte

  Serial.write(y/4);//第2個byte

  Serial.write (sw); //第3個byte

  delay(20);//1000ms/20ms => 50fps,變慢了

}


沒有留言:

張貼留言