Photosynthetic Life & Sitting FSR (4)

ian's picture

Description

Create an interesting visualization using input from a pot, FSR, or photocell; make a mechanical construction for an FSR. 

The first portion is a "photosynthetic" adaptation of the zero-player game, Conway's Game of Life. The photocell controls the rules to the game, making it more hostile for life to exist when there is less light, or more accommodating when there is more light. In reality, the true game is much more on the less-populated side, so there are many more levels of life populating most of the screen, and only one level with less than the original rules to the game. Thus, Photosynthetic Life needs mostly shade, with a little amount of light, to develop as it does in the original game. This game is best manipulated by shading the photocell by hand, as it responds very quickly. If it were to be controlled by sunlight, for example, the rules should be much more strict to the original, and only slightly increase the probability of creating life, so the evolution would be much slower.

The mechanical construction uses an FSR to detect when a person is sitting, shifting in their seat, or even moving their legs, depending on the location that the sensor is placed. A sliver of a wine cork is place over the sensor, then an old CD, then a cloth. The cork is necessary to concentrate the force from the CD, which is thin enough to not be felt, and stiff enough to transfer the force from a larger area. By tweaking the parameters of the arduino side of the photosynthetic life code, a pressure-sensitive game of life can be played, or otherwise, the FSR can be used with the Ball Paint code to manipulate the ball size as you shift in your seat, or perhaps, dance in your seat.

Components

  • Photocell
  • 10 kΩ resistor
  • Processing
  • Arduino
  • Cloth
  • CD-ROM
  • thin, coin shaped sliver of cork
  • FSR

 

Arduino Code

#define inpin 0

#define highval 700
int inval = 0;
int outvalold = 0;
int outvalnew = 0;
 
void setup() {
  Serial.begin(9600);
}
 
void loop() {
  inval = analogRead(inpin);
  outvalnew = map(inval, 0, highval, 0, 5);
//  Serial.println(inval); // diagnostic
  if (outvalold != outvalnew) {
    Serial.println(outvalnew);
    outvalold = outvalnew; }
delay(10); }
 

Processing Code

// Ian Leighton

// TUI 2011-09-27
// Homework: Arduino + Processing
 
/**
 uses a photocell to control the rules for conway's game of life. Modified from:
 
 * Conway's Game of Life 
 * by Mike Davis. 
 * 
 * This program is a simple version of Conway's 
 * game of Life.  A lit point turns off if there 
 * are fewer than two or more than three surrounding 
 * lit points.  An unlit point turns on if there 
 * are exactly three lit neighbors.  The 'density' 
 * parameter determines how much of the board will 
 * start out lit.  
 */
 
// get serial working.
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "/dev/tty.usbmodem621"; // or "COM5"
Serial port;
//String buf="";
int cr = 13;  // ASCII return   == 13
int lf = 10;  // ASCII linefeed == 10
 
// game of life variables:
int born = 3;
int low = 2;
int high = 3;
 
int sx, sy; 
float density = 0.5; 
int[][][] world;
 
void setup() 
  size(1280, 800, P2D);
  frameRate(12);
  sx = width;
  sy = height;
  world = new int[sx][sy][2]; 
  println(Serial.list());
  port = new Serial(this, Serial.list()[0], 9600);
  //  port.bufferUntil(lf);
 
  // Set random cells to 'on' 
  for (int i = 0; i < sx * sy * density; i++) { 
    world[(int)random(sx)][(int)random(sy)][1] = 1;
  }
 
void draw() 
  background(0); 
  // Drawing and update cycle 
  for (int x = 0; x < sx; x=x+1) { 
    for (int y = 0; y < sy; y=y+1) { 
      //if (world[x][y][1] == 1) 
      // Change recommended by The.Lucky.Mutt
      if ((world[x][y][1] == 1) || (world[x][y][1] == 0 && world[x][y][0] == 1)) 
      { 
        world[x][y][0] = 1; 
        set(x, y, #FFFFFF);
      } 
      if (world[x][y][1] == -1) 
      { 
        world[x][y][0] = 0;
      } 
      world[x][y][1] = 0;
    }
  } 
// get new parameters
int bornGet = born; int lowGet = low; int highGet = high;
 
  // Birth and death cycle 
  for (int x = 0; x < sx; x=x+1) { 
    for (int y = 0; y < sy; y=y+1) { 
      int count = neighbors(x, y); 
      if (count == bornGet && world[x][y][0] == 0) 
      { 
        world[x][y][1] = 1;
      } 
      if ((count < lowGet || count > highGet) && world[x][y][0] == 1) 
      { 
        world[x][y][1] = -1;
      }
    }
  }
 
// Count the number of adjacent cells 'on' 
int neighbors(int x, int y) 
  return world[(x + 1) % sx][y][0] + 
    world[x][(y + 1) % sy][0] + 
    world[(x + sx - 1) % sx][y][0] + 
    world[x][(y + sy - 1) % sy][0] + 
    world[(x + 1) % sx][(y + 1) % sy][0] + 
    world[(x + sx - 1) % sx][(y + 1) % sy][0] + 
    world[(x + sx - 1) % sx][(y + sy - 1) % sy][0] + 
    world[(x + 1) % sx][(y + sy - 1) % sy][0];
 
 
// called whenever serial data arrives
// assigns new parameters depending on a 1-5 serial input.
void serialEvent(Serial p) {
  char c = p.readChar();
  if (c != lf && c != cr) {
    switch (c) {
    case '0':
      born = 3; 
      low = 2; 
      high = 2;
      println(0);
      break;
    case '1':
      born = 3; 
      low = 2; 
      high = 3;
      println(1);
      break;
    case '2':
      born = 2; 
      low = 1; 
      high = 2;
      println(2);
      break;
    case '3':
      born = 2; 
      low = 2; 
      high = 3;
      println(3);
      break;
    case '4':
      born = 3; 
      low = 2; 
      high = 4;
      println(4);
      break;
    case '5':
      born = 3; 
      low = 2; 
      high = 5;
      println(5);
      break;
    }
  }
}
 

 

photosynthetic life
photocell circuit detail
life screenshot
FSR mechanical construction
close up of FSR mechanical construction
0
Your rating: None