Homework - Programming

Johnparayno's picture

 

/* Initially I wanted to use all my all three sensor and apply the following mapping – but I have not yet succeed to distinguish between the channels for each sensor(POT, FSR, PC).

So what I am delivering is 3 separate functionalities – so e.g. if I want to use the POT, I comment out the rest of the Arduino code below: (as seen with the FSR), and then I run the corresponding Prossessing script

//--------------------------------------------------------------------------------
// ARDUINO PROGRAM CODE

int potPin = 0;
int FSR = 5;
int PC = 2;
int updateSpeed = 50;

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

void loop(void) {      
//  int potVal = map(analogRead(potPin), 0, 1023, 0,225); 
//  Serial.println(potVal);

  int FSRVal = map(analogRead(FSR), 0, 1023, 0,225);
  Serial.println(FSRVal);

//  int PCVal = map(analogRead(PC), 0, 1023, 0,225);
//  Serial.println(PCVal);

    delay(updateSpeed);
}

//--------------------------------------------------------------------------------

//PROCESSOR CODE
import processing.serial.*;
Serial port;
float brightness = 0;

void setup() { 
  size(300,300);
  port = new Serial(this,"/dev/tty.usbmodemfd131", 9600);
  port.bufferUntil('\n');
}

//////////////////////////////////////////////////////

// 1 – POT functionality in Processing
// Change the size of ball

void draw() {
    background(500,0 , 0);   
    ellipse(300/2,  300/2, brightness , brightness);
    smooth();
    fill(225);
}

// 2 – FSR functionality in Processing
// control the ball color
/*

void draw() {
    background(0,0, 500);   
    ellipse(300/2,  300/2, 100 , 100);
    smooth();
    fill(brightness);
}
*/

// 3 – PC functionality in Processing
// control background color
/*

void draw() {
    background(brightness*10,0, 0);   
    ellipse(300/2,  300/2, 100 , 100);
    smooth();
    fill(225);
}*/

//////////////////////////////////////////////////////
void serialEvent (Serial port) {
brightness = float(port.readStringUntil('\n'));
}

 

Screen shot 2011-09-27 at 14.22.09 .png
Screen shot 2011-09-27 at 14.21.22 .png
Screen shot 2011-09-27 at 14.21.07 _0.png
foto_0.JPG
0
Your rating: None