2021年1月4日 星期一

WEEK1313131313

 WEEK13


今天做的是joystick按下會發出聲音,然後用0跟1判斷按跟沒按,最後按下joystickcl會改變顏色
一樣是利用arduino搭配processing

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("現在你得的其實是:"+now);
    if( now == '1') button;
    else butten=0;
  }
  if(button=1) background(255,0,0);
  else background(255);
}


arduino

void setup() {
  Serial.begin(9600);
  pinMode(2,INPUT_PULLUP);
  pinMode(8,OUTPUT);
}
int state=0;
void loop()
{
  if(dugutalRead(1)==LOW && state==0)
  {
    state=1;
    Serial.write("1");
  }
  if(dugutalRead(2)==HIGH && state==1)
  {
    state=0;
    Serial.write("0");
  }
  delay(100);
}

沒有留言:

張貼留言