2017年11月27日 星期一

第十一週

WEEK11  課堂der筆記筆記


作業
1.安裝驅動程式




2.







3.

程式碼:


void setup() {
  //start serial connection
  Serial.begin(9600);
  //configure pin2 as an input and enable the internal pull-up resistor
  pinMode(2, INPUT_PULLUP);
  pinMode(13, OUTPUT);

}

void loop() {
  //read the pushbutton value into a variable
  int sensorVal = digitalRead(2);
  //print out the value of the pushbutton
//  if(sensorVal==0) Serial.println("I Press it");
//  else Serial.println("I didn't Press it");
    Serial.print(sensorVal);

  // Keep in mind the pullup means the pushbutton's
  // logic is inverted. It goes HIGH when it's open,
  // and LOW when it's pressed. Turn on pin 13 when the
  // button's pressed, and off when it's not:
  if (sensorVal == HIGH) {
    digitalWrite(13, LOW);
  } else {
    digitalWrite(13, HIGH);
  }
  delay(33);
}


程式碼:
import processing.serial.*;

Serial myPort;
int val;

void setup(){
  size(600,400);
  myPort = new Serial(this, "COM6", 9600);
}
void draw(){
  if ( myPort.available() > 0) {
    val = myPort.read();
    println(val);
    if(val=='0') background(255,0,0);
    else background(0,255,0);
  }
}



4.

程式碼:

int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  Serial.println(sensorValue);
  // turn the ledPin on
}
import processing.serial.*;

Serial myPort;
int val;

void setup(){
  size(600,400);
  myPort = new Serial(this, "COM6", 9600);
}
int x=0;
void draw(){
  background(255);
  if ( myPort.available() > 0) {
    val = myPort.read();
    println(val);
    x=val;
  }
  ellipse(x*3,200,100,100);
}























沒有留言:

張貼留言