Processing arduino 1: Difference between revisions

From Medien Wiki
(Created page with '<pre> →‎* * Liesst Poti auf dem Arduino aus und färbt das Rechteck danach: import processing.serial.*; Serial myPort; // Create object from Serial class int val; //…')
 
m (changed pre to source)
Line 1: Line 1:
<pre>
<source lang="C">
/**
/**
  * Liesst Poti auf dem Arduino aus und färbt das Rechteck danach
  * Liest Poti auf dem Arduino aus und färbt das Rechteck danach
  */
  */


Line 46: Line 46:
*/
*/


</pre>
</source>

Revision as of 04:17, 29 November 2009

/**
 * Liest Poti auf dem Arduino aus und färbt das Rechteck danach
 */


import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port

void setup() 
{
  size(200, 200);
  String portName = Serial.list()[0]; // die Zahl 0 ist abhänig vom USB Device
  myPort = new Serial(this, portName, 9600);
  myPort.bufferUntil('\n');
}

void draw(){}

        
void serialEvent(Serial myPort) {
  String inString = myPort.readStringUntil('\n');
  if(inString != null) {
    inString = trim(inString);
    float inNumber = float(inString);
 
    fill(map(inNumber,0,1023,0,255));                
    rect(50, 50, 100, 100);
  }
}

/* Arduino Code

int potPin = 0;                       
void setup() {
  Serial.begin(9600);    
}

void loop() {
  Serial.println(analogRead(potPin));  
  delay(100);                          
}

*/