2020年12月7日 星期一

week ╯13 ╮

 week13👀❤✌👤

♥2槽輸入,8槽喇叭輸出,按下按鈕後state=1、並輸出1,放開則state=0、並輸出0

♥程式碼-

#define button 2

#define buzzer 8


void setup()

{

  Serial.begin(9600);

  pinMode(2,INPUT_PULLUP);

  pinMode(8,OUTPUT);

}

int state=0;

void loop()

{

  if(digitalRead(2)==LOW && state==0)

  {

    state=1;

    Serial.write("1");

  }

  if(digitalRead(2)==HIGH && state==1)

  {

   state=0;

    Serial.write=("0");;

  }

  delay(100);

}

---

♥processing

♥程式碼-

import processing.serial.*;

Serial myPort;

void setup(){

    size(300,200);

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

}

int button=0;

void draw(){

  if( myPort.available()>0 ){///收資料

    int now = myPort.read();

    println("right now you read is:"+now);

    if( now == '1') button=1;

    else button=0;

  }

  if (button==1) background(255,0,0)

  else background(255);

}


---

♥download->UDP

♥點擊方框就能將資料傳輸到"120.125.70.53"

♥程式碼-

import hypermedia.net.*;

UDP udp;

void setup(){

    size(300,200);

    udp= new UDP(this, 6000);

    udp.send("hello world", "120.125,70,53", 6100);

}

void draw(){

 

}

void mousePressed(){

   udp.send("mousePressed","120.125.70.53", 6100); 

}



沒有留言:

張貼留言