Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

09 AnalogIn

16. November 2011

Aufgabe

2. Lest die Werte eines Potetiometers an einem analogen Pin ein und verändert die Blinkgeschwindigkeit einer LEDMaterial: Potentiometer, Widerstand (10kOhm), LED, Vorwiderstand CODE
// set pin numbers:
const int analogIn =  0;
const int ledPin =  11;

int potiVal = 0;
float foo = 0;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  potiVal = analogRead(analogIn);
  //foo = map(potiVal,0,1023,0,255);
  foo = potiVal;
  digitalWrite(ledPin, HIGH);
  delay(foo);
  digitalWrite(ledPin, LOW);
  delay(foo);
  Serial.print(foo);
  Serial.println();
}

Aufgabe

5. Lest die Werte des Sensors in Processing ein und visualisiert diese. Achtet dabei auf eine nachvollziehbare Art der Visualisierung. Material: Sensor, Widerstand, Processing Zwei Drucksensoren (Wiederstände) wurden in einer 3D-Visualisierung für die Rotation von der x- und y-Achse eingesetzt. Arduino
// set pin numbers:
const int analogIn1 =  0;
const int analogIn2 =  1;

int potiVal1 = 0;
int potiVal2 = 0;
int out1 = 0;
int out2 = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  potiVal1 = analogRead(analogIn1);
  potiVal2 = analogRead(analogIn2);
  out1 = map(potiVal1,0,1024,0,6);
  out2 = map(potiVal2,0,1024,0,6);
  Serial.print(out1);
  Serial.print(',');
  Serial.print(out2);
  Serial.print(',');
  Serial.println();
}
Processing
import processing.serial.*;

Serial myPort;
float potiVal1 = 0;
float potiVal2 = 2;

PImage[] imageList = null;
int listLenght = 32;
int factor = 1;
float rotx;
float roty;
boolean done;
boolean switchFlag = false;
int posX = 1;
int posY = 1;
int signY = -1;

void setup() {
  size(500, 500, P3D);

  println(Serial.list());
  myPort = new Serial(this,Serial.list()[0],9600);

  done = false;
  PImage tmpImage;
  color col;
  int r,g,b,a;

  //init
  switchFlag = true;
  rotx = 100*TWO_PI + PI/4;
  roty = 100*TWO_PI + PI/4;
  imageList = new PImage[listLenght];

  for(int i=0; i < listLenght; i++) {
    tmpImage = loadImage("./pollen/image"+i+".jpg");
    tmpImage.loadPixels();
    imageList[i] = createImage(tmpImage.width, tmpImage.height, ARGB);
    imageList[i].loadPixels();
    for(int j=0; j> 16) & 0xff;
      g = (col >> 8) & 0x88;
      b = col & 0x22;
      a = (r+g+b)/3;
      col = color(r,g,b,a);
      imageList[i].pixels[j] = col;
    }
    imageList[i].updatePixels();
  }

  done = true;
  noStroke();
}

void draw() {
  background(30);
  if(done) {
    background(30);
    ortho(0, width, 0, height, -10, 10);
    translate(width, height);
    rotateX(rotx);
    rotateY(roty);

    if(switchFlag) {
      for(int i=0; i0; i--) {
        beginShape();
          texture(imageList[i]);
          vertex(-100, -100,i, 0, 0);
          vertex(100, -100,i, imageList[i].width, 0);
          vertex(100, 100,i, imageList[i].width, imageList[i].height);
          vertex(-100, 100,i, 0, imageList[i].height);
         endShape();
      }
    }
  } else {
    println("loading");
  }
}

void serialEvent(Serial myPort) {
  if(myPort.available() > 0) {
    String completeString = myPort.readStringUntil(10);
    if(completeString != null) {
      trim(completeString);
      println(completeString);
      int[] seperateVal = int(split(completeString,','));

      potiVal1 = seperateVal[0];
      potiVal2 = seperateVal[1];

      float rate = 0.01;

      rotx += (potiVal1 * rate);
      roty += (potiVal2 * rate)*signY;

      int fooPosY = int((roty+PI/2)/PI)%2;
      int fooPosX = int((rotx+PI/2)/PI)%2;
      if(posX != fooPosX) {
        posX = fooPosX;
        signY *= -1;
        switchFlag = !switchFlag;
      }
      if(posY != fooPosY) {
        posY = fooPosY;
        switchFlag = !switchFlag;
      }
    }
  }
}