Class 05- Lab assignments 13 14

Lab assignment 13:  CapacitiveSensor . Using the  body
The wires and the foil make a live capacitor as the body approaches the foil the capitance changes.
Key terms:
// import the library (must be located in the Arduino/libraries directory)
#include <CapacitiveSensor.h>

// create an instance of the library
// pin 4 sends electrical energy
// pin 2 senses senses a change
CapacitiveSensor capSensor = CapacitiveSensor(4, 2);

// open a serial connection
Serial.begin(9600);
// set the LED pin as an output
pinMode(ledPin, OUTPUT);
}

void loop() {
// store the value reported by the sensor in a variable
long sensorValue = capSensor.capacitiveSensor(30);

 

 

Lab assignment 14:  Set Serial communication between Arduinio+Processing
Use the values from a potentiometer and pass them directly to processing to control the color of a sketch
Key terms:

// initialize serial communication
Serial.begin(9600);
}

void loop() {
// read the value of A0, divide by 4 and send it as a byte over the
// serial connection
//Serial.print(“POTENTIOMETER =”);
// Serial.println(analogRead(0) / 4.0);
Serial.write(analogRead(0) / 4.0);
delay(5);

PROCESSING:

// import the serial library
import processing.serial.*;

// create an instance of the serial library
Serial myPort;

// create an instance of PImage
PImage logo;

// load the Arduino logo into the PImage instance
logo = loadImage(“http://www.arduino.cc/arduino_logo.png”);

// print a list of available serial ports to the Processing status window

println(“Available serial ports:”);
println(Serial.list());

// Tell the serial object the information it needs to communicate with the
// Arduino. Change Serial.list()[0] to the correct port corresponding to
// your Arduino board. The last parameter (e.g. 9600) is the speed of the
// communication. It has to correspond to the value passed to
// Serial.begin() in your Arduino sketch.
myPort = new Serial(this, Serial.list()[0], 9600);