Pressure Painting (Lab 04)

Description:

It is often ill-advised for a painter to apply much tension to their brush strokes. Not only does it harm the integrity of the bristles, but it also constricts the artist’s technique and ultimately the nature of their work. For this lab, I used an FSR potentiometer and Processing to indicate when there’s too much tension applied to the brush in a brushstroke. The LEDs also blink at a heightened pace when too much pressure is applied, as to alert the artist if they’re too preoccupied looking down at what they are painting to notice the color on the screen.

Components Used:

  • 1 Arduino
  • 3 LEDs (red, green, and blue)
  • 3 Resistors (220Ω)
  • 1 Resistor (10kΩ)
  • 1 Breadboard
  • 1 FSR Potentiometer
  • 1 post-it sheet

Code:

/*
 This example is meant to read three analog sensors (potentiometers are easiest)
 and sends their values serially. The Processing and Max/MSP programs at the bottom
 take those three values and use them to change the background color of the screen.

 [Dina's addition:
 In the event of only one potentiometer being attached, all three analog inputs
 will be affected in the same way.]

 The circuit:
 * potentiometers attached to analog inputs 0, 1, and 2

 http://www.arduino.cc/en/Tutorial/VirtualColorMixer

 created 2 Dec 2006
 by David A. Mellis
 modified 30 Aug 2011
 by Tom Igoe and Scott Fitzgerald
 modified on 24 Sept 2016
 by Dina Bseiso

 This example code is in the public domain.

 */

int sensorPin = A0; // select the input pin for the potentiometer for pulse
int sensorValue = 0; // variable to store the value coming from the sensor



const int redledPin = 9;
const int blueledPin = 10;
const int greenledPin = 11; // select the pin for the LED

void setup() {
 // declare the ledPin as an OUTPUT:
 pinMode(redledPin, OUTPUT);
 pinMode(blueledPin, OUTPUT);
 pinMode(greenledPin, OUTPUT);
 Serial.begin(9600);
}

void loop() {
 Serial.print(analogRead(redledPin));
 Serial.print(",");
 Serial.print(analogRead(greenledPin));
 Serial.print(",");
 Serial.println(analogRead(blueledPin));
 // read the value from the sensor:
 sensorValue = analogRead(sensorPin);
 // turn the ledPin on
 digitalWrite(redledPin, HIGH);
 digitalWrite(blueledPin, HIGH);
 digitalWrite(greenledPin, HIGH); 
 // stop the program for <sensorValue> milliseconds:
 delay(sensorValue);
 // turn the ledPin off:
 digitalWrite(redledPin, LOW);
 digitalWrite(blueledPin, LOW);
 digitalWrite(greenledPin, LOW);
 // stop the program for for <sensorValue> milliseconds:
 delay(sensorValue);
}

/* PROCESSING SKETCH
 * Arduino Painting Tension
 * (from Arduino Ball, modified 2008, and then by Dina on 2016)
 * ---------------------- 
 *
 * Change the color on the screen depending on
 * the amount of pressure applied to an FSR.
 *
 * Created 24 September 2016
 * Dina Bseiso
 */
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "/dev/cu.usbmodem1441"; // or "COM5"
Serial myPort;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10



float redValue = 0; // red value
float greenValue = 0; // green value
float blueValue = 0; // blue value

int serialVal = 0;
int serialValAmplified = 0;


void setup() {
 size(300,300);
 frameRate(10);
 smooth();
 ellipseMode(CENTER);
 background(40,40,40);
 noStroke();
 myPort = new Serial(this, portname, 9600); 
}

void draw() {
 // set the background color with the color values:
 background(redValue, greenValue, blueValue);
}

// called whenever serial data arrives
void serialEvent(Serial myPort) {
 // get the ASCII string:
 String inString = myPort.readStringUntil('\n');
 println(inString);

 if (inString != null) {
 // trim off any whitespace:
 inString = trim(inString);
 // split the string on the commas and convert the
 // resulting substrings into an integer array:
 float[] colors = float(split(inString, ","));
 // if the array has at least three elements, you know
 // you got the whole thing. Put the numbers in the
 // color variables:
 if (colors.length >=3) {
 //println(colors);
 // map them to the range 0-255:
 if (colors[0] >= 700) {
 blueValue = map(colors[2], 0, 1023, 150, 255);
 greenValue = map(colors[1], 1023, 0, 75, 150);
 redValue = map(colors[0], 1023, 0, 0, 75);
 }
 else if (colors[0] >= 300) {
 greenValue = map(colors[1], 1023, 0, 150, 255);
 blueValue = map(colors[2], 0, 1023, 75, 150);
 redValue = map(colors[0], 1023, 0, 75, 150);
 }
 else if (colors[0] >= 0) {
 redValue = map(colors[0], 1023, 0, 150, 255);
 greenValue = map(colors[1], 0, 1023, 75, 175);
 blueValue = map(colors[2], 0, 1023, 0, 75);
 }
 }
 }
}

img_6255

Pressure Painting


			

Leave a Reply