IFD:PhysicalComp2011/Dianna Mertz: Difference between revisions

From Medien Wiki
mNo edit summary
mNo edit summary
Line 38: Line 38:
import processing.serial.*;
import processing.serial.*;
int incomingVal;
int incomingVal;
int level;
int r;
int r;
int b;
int b;
Line 46: Line 47:
   size(255,255);
   size(255,255);
   dataTable = new Table("data.tsv");
   dataTable = new Table("data.tsv");
  //rowCount = dataTable.getRowCount();
   myPort = new Serial(this,"/dev/tty.usbmodem411",9600);
   myPort = new Serial(this,"/dev/tty.usbmodem411",9600);
}
}
Line 54: Line 56:
     incomingVal = myPort.read();
     incomingVal = myPort.read();
   }
   }
   fill(incomingVal);
  level = height - incomingVal;
   rect(0,height-incomingVal,width,height);
   fill(level);
   rect(0,level,width,height);


   PrintWriter output = createWriter("data/data.tsv");
   PrintWriter output = createWriter("data/data.tsv");
   output.println("Pasta:" +incomingVal+ " Rice:" +r+ " Bulgar:" +b+ " Quinoa:" +q+ " Oats:" +o );
   output.println("Pasta:" +level+ " Rice:" +r+ " Bulgar:" +b+ " Quinoa:" +q+ " Oats:" +o );
   output.flush();
   output.flush();  
  output.close(); 
}
}
</source>
</source>

Revision as of 11:47, 23 January 2012

Need

Question: Is there enough flour and sugar at home to make a cake for your friend's birthday tomorrow? Or do you need to stop at the store on your way home?

Concept

Design containers for pantry bulk items that relay content levels to smart phone app in real time.

Equipment

  • Arduino
  • Sharp GP2D120XJ00F Analog Distance Sensor 4-30cm
  • Container
  • Computer

Prototype

(coming soon)

Code

Arduino

int IRpin = 1;   
int val = 0; 
                                          
void setup() {
Serial.begin(9600);                             
}
   
void loop() {
float volts = analogRead(IRpin)*0.00322265624;
float distance = 12.21*pow(volts, -1.15);         
Serial.println(distance);                                                             
}

Processing

Tab 1
Serial myPort;
Table dataTable;
import processing.serial.*;
int incomingVal;
int level;
int r;
int b;
int q;
int o;
 
void setup(){
  size(255,255);
  dataTable = new Table("data.tsv");
  //rowCount = dataTable.getRowCount();
  myPort = new Serial(this,"/dev/tty.usbmodem411",9600);
}
 
void draw(){
  background(0);
  while(myPort.available() > 0){
    incomingVal = myPort.read();
  }
  level = height - incomingVal;
  fill(level);
  rect(0,level,width,height);

  PrintWriter output = createWriter("data/data.tsv");
  output.println("Pasta:" +level+ " Rice:" +r+ " Bulgar:" +b+ " Quinoa:" +q+ " Oats:" +o );
  output.flush(); 
}
Tab 2

Ben Fry's Table

References

Reference for Sharp GP2D120XJ00F Analog Distance Sensor 4-30cm
Arduino – Using a Sharp IR Sensor for Distance Calculation