Virtual Stress Ball(Sponge)
Description:
For this assignment, I decided to build a virtual stress ball. To me, this meant visualizing my squeezing of the ball, with some indicator of stress. I chose to fade from a happy face to an angry face the harder I squeezed. Animation was done with Max/MSP/Jitter (specifically Jitter), by cross-fading between two images. The amount of fade was dictated by a 0 to 1 floating point value. This meant I had to convert from the 0 to 1023 range output by analogRead to the 0 to 1 range needed by Max. I used a more general version of the built in map function to do this (since map does not work for floating point numbers). I was a little afraid of damaging the the FSR so I simulated the ball with piece of a kitchen sponge, making it a virtual stress sponge.
Materials:
- Arduino x1
- BreadBoard x1
- USB-cable x1
- Force Sensitive Resistor x1
- Resistor x1
- jumper-cables
- an animation program to cross fade between images (Max patch is included, but other programs could be used)
Arduino Code:
void setup() { // initialize the serial communication: Serial.begin(9600); } float mapfloat(long x, long in_min, long in_max, long out_min, long out_max) { return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + out_min; } void loop() { // send the value of analog input 0: Serial.println(mapfloat(analogRead(0), 0.0, 1023.0, 0.0, 1.0)); // wait a bit for the analog-to-digital converter // to stabilize after the last reading: delay(2); }
MaxPatch:
{ "boxes" : [ { "box" : { "maxclass" : "toggle", "outlettype" : [ "int" ], "id" : "obj-3", "numinlets" : 1, "patching_rect" : [ 418.0, 159.0, 20.0, 20.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "newobj", "text" : "p serial_in", "outlettype" : [ "float" ], "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-1", "numinlets" : 1, "patching_rect" : [ 418.0, 182.0, 65.0, 20.0 ], "numoutlets" : 1, "patcher" : { "fileversion" : 1, "rect" : [ 115.0, 281.0, 640.0, 480.0 ], "bglocked" : 0, "defrect" : [ 115.0, 281.0, 640.0, 480.0 ], "openrect" : [ 0.0, 0.0, 0.0, 0.0 ], "openinpresentation" : 0, "default_fontsize" : 12.0, "default_fontface" : 0, "default_fontname" : "Arial", "gridonopen" : 0, "gridsize" : [ 15.0, 15.0 ], "gridsnaponopen" : 0, "toolbarvisible" : 1, "boxanimatetime" : 200, "imprint" : 0, "enablehscroll" : 1, "enablevscroll" : 1, "devicewidth" : 0.0, "boxes" : [ { "box" : { "maxclass" : "flonum", "outlettype" : [ "float", "bang" ], "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-23", "numinlets" : 1, "patching_rect" : [ 318.0, 431.0, 50.0, 20.0 ], "numoutlets" : 2 } } , { "box" : { "maxclass" : "inlet", "outlettype" : [ "int" ], "id" : "obj-18", "numinlets" : 0, "patching_rect" : [ 249.0, 15.0, 25.0, 25.0 ], "numoutlets" : 1, "comment" : "" } } , { "box" : { "maxclass" : "outlet", "id" : "obj-1", "numinlets" : 1, "patching_rect" : [ 319.0, 474.0, 25.0, 25.0 ], "numoutlets" : 0, "comment" : "" } } , { "box" : { "maxclass" : "comment", "text" : "Graph\n\nThis patch takes a string, containing ASCII formatted number from 0 to 1023, with a carriage return and linefeed at the end. It converts the string to an integer and graphs it.\n\ncreated 2006\nby David A. Mellis\nmodified 14 Apr 2009\nby Scott Fitzgerald and Tom Igoe", "linecount" : 10, "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-32", "numinlets" : 1, "patching_rect" : [ 494.0, 21.0, 344.0, 144.0 ], "numoutlets" : 0 } } , { "box" : { "maxclass" : "newobj", "text" : "select 0 1", "outlettype" : [ "bang", "bang", "" ], "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-30", "numinlets" : 1, "patching_rect" : [ 342.0, 95.0, 62.0, 20.0 ], "numoutlets" : 3 } } , { "box" : { "maxclass" : "comment", "text" : "click here to close the serial port", "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-26", "numinlets" : 1, "patching_rect" : [ 427.0, 246.0, 206.0, 20.0 ], "numoutlets" : 0 } } , { "box" : { "maxclass" : "comment", "text" : "click here to open the serial port", "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-27", "numinlets" : 1, "patching_rect" : [ 427.0, 220.0, 206.0, 20.0 ], "numoutlets" : 0 } } , { "box" : { "maxclass" : "message", "text" : "close", "outlettype" : [ "" ], "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-21", "numinlets" : 2, "patching_rect" : [ 342.0, 246.0, 39.0, 18.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "message", "text" : "port a", "outlettype" : [ "" ], "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-19", "numinlets" : 2, "patching_rect" : [ 364.0, 220.0, 41.0, 18.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "comment", "text" : "Click here to get a list of serial ports", "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-2", "numinlets" : 1, "patching_rect" : [ 427.0, 194.0, 207.0, 20.0 ], "numoutlets" : 0 } } , { "box" : { "maxclass" : "comment", "text" : "Here's the number from Arduino's analog input", "linecount" : 2, "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-3", "numinlets" : 1, "patching_rect" : [ 168.0, 424.0, 138.0, 34.0 ], "numoutlets" : 0 } } , { "box" : { "maxclass" : "comment", "text" : "Convert ASCII to symbol", "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-4", "numinlets" : 1, "patching_rect" : [ 394.0, 393.0, 147.0, 20.0 ], "numoutlets" : 0 } } , { "box" : { "maxclass" : "comment", "text" : "Convert integer to ASCII", "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-5", "numinlets" : 1, "patching_rect" : [ 394.0, 370.0, 147.0, 20.0 ], "numoutlets" : 0 } } , { "box" : { "maxclass" : "newobj", "text" : "fromsymbol", "outlettype" : [ "" ], "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-7", "numinlets" : 1, "color" : [ 1.0, 0.890196, 0.090196, 1.0 ], "patching_rect" : [ 317.0, 396.0, 74.0, 20.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "newobj", "text" : "itoa", "outlettype" : [ "int" ], "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-8", "numinlets" : 3, "color" : [ 1.0, 0.890196, 0.090196, 1.0 ], "patching_rect" : [ 317.0, 370.0, 46.0, 20.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "newobj", "text" : "zl group 4", "outlettype" : [ "", "" ], "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-9", "numinlets" : 2, "patching_rect" : [ 317.0, 347.0, 64.0, 20.0 ], "numoutlets" : 2 } } , { "box" : { "maxclass" : "newobj", "text" : "select 10 13", "outlettype" : [ "bang", "bang", "" ], "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-10", "numinlets" : 1, "patching_rect" : [ 259.0, 296.0, 77.0, 20.0 ], "numoutlets" : 3 } } , { "box" : { "maxclass" : "toggle", "outlettype" : [ "int" ], "id" : "obj-11", "numinlets" : 1, "patching_rect" : [ 259.0, 58.0, 15.0, 15.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "newobj", "text" : "qmetro 10", "outlettype" : [ "bang" ], "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-12", "numinlets" : 2, "patching_rect" : [ 259.0, 95.0, 65.0, 20.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "message", "text" : "print", "outlettype" : [ "" ], "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-13", "numinlets" : 2, "patching_rect" : [ 384.0, 194.0, 36.0, 18.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "newobj", "text" : "serial a 9600", "outlettype" : [ "int", "" ], "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-14", "numinlets" : 1, "patching_rect" : [ 259.0, 270.0, 84.0, 20.0 ], "numoutlets" : 2 } } , { "box" : { "maxclass" : "comment", "text" : "Read serial input buffer every 10 milliseconds", "linecount" : 2, "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-15", "numinlets" : 1, "patching_rect" : [ 68.0, 87.0, 185.0, 34.0 ], "numoutlets" : 0 } } , { "box" : { "maxclass" : "comment", "text" : "If you get newline (ASCII 10), send the list. If you get return (ASCII 13) do nothing. Any other value, add to the list", "linecount" : 3, "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-16", "numinlets" : 1, "patching_rect" : [ 347.0, 284.0, 320.0, 48.0 ], "numoutlets" : 0 } } , { "box" : { "maxclass" : "comment", "text" : "Click to open/close serial port and start/stop patch", "linecount" : 2, "fontname" : "Arial", "fontsize" : 12.0, "id" : "obj-17", "numinlets" : 1, "patching_rect" : [ 286.0, 47.0, 199.0, 34.0 ], "numoutlets" : 0 } } ], "lines" : [ { "patchline" : { "source" : [ "obj-8", 0 ], "destination" : [ "obj-7", 0 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-9", 0 ], "destination" : [ "obj-8", 0 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-10", 0 ], "destination" : [ "obj-9", 0 ], "hidden" : 0, "midpoints" : [ 268.5, 323.0, 326.5, 323.0 ] } } , { "patchline" : { "source" : [ "obj-10", 2 ], "destination" : [ "obj-9", 0 ], "hidden" : 0, "midpoints" : [ 326.5, 335.0, 326.5, 335.0 ] } } , { "patchline" : { "source" : [ "obj-14", 0 ], "destination" : [ "obj-10", 0 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-12", 0 ], "destination" : [ "obj-14", 0 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-11", 0 ], "destination" : [ "obj-12", 0 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-13", 0 ], "destination" : [ "obj-14", 0 ], "hidden" : 0, "midpoints" : [ 393.5, 215.5, 268.5, 215.5 ] } } , { "patchline" : { "source" : [ "obj-19", 0 ], "destination" : [ "obj-14", 0 ], "hidden" : 0, "midpoints" : [ 373.5, 243.5, 268.5, 243.5 ] } } , { "patchline" : { "source" : [ "obj-21", 0 ], "destination" : [ "obj-14", 0 ], "hidden" : 0, "midpoints" : [ 351.5, 266.5, 268.5, 266.5 ] } } , { "patchline" : { "source" : [ "obj-30", 0 ], "destination" : [ "obj-21", 0 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-30", 1 ], "destination" : [ "obj-19", 0 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-11", 0 ], "destination" : [ "obj-30", 0 ], "hidden" : 0, "midpoints" : [ 268.0, 86.0, 351.5, 86.0 ] } } , { "patchline" : { "source" : [ "obj-18", 0 ], "destination" : [ "obj-11", 0 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-7", 0 ], "destination" : [ "obj-23", 0 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-23", 0 ], "destination" : [ "obj-1", 0 ], "hidden" : 0, "midpoints" : [ ] } } ] } , "saved_object_attributes" : { "default_fontname" : "Arial", "fontname" : "Arial", "default_fontsize" : 12.0, "fontface" : 0, "fontsize" : 12.0, "default_fontface" : 0, "globalpatchername" : "" } } } , { "box" : { "maxclass" : "jit.fpsgui", "outlettype" : [ "", "" ], "fontname" : "Arial", "fontsize" : 11.595187, "id" : "obj-13", "numinlets" : 1, "patching_rect" : [ 380.0, 529.0, 80.0, 35.0 ], "numoutlets" : 2 } } , { "box" : { "maxclass" : "message", "text" : "stop", "outlettype" : [ "" ], "fontname" : "Arial", "fontsize" : 11.595187, "id" : "obj-14", "numinlets" : 2, "patching_rect" : [ 293.375, 138.0, 32.5, 18.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "message", "text" : "stop", "outlettype" : [ "" ], "fontname" : "Arial", "fontsize" : 11.595187, "id" : "obj-15", "numinlets" : 2, "patching_rect" : [ 167.581253, 138.0, 32.5, 18.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "newobj", "text" : "print", "fontname" : "Arial", "fontsize" : 11.595187, "id" : "obj-18", "numinlets" : 1, "patching_rect" : [ 81.0, 282.0, 33.0, 20.0 ], "numoutlets" : 0 } } , { "box" : { "maxclass" : "message", "text" : "getxfade", "outlettype" : [ "" ], "fontname" : "Arial", "fontsize" : 11.595187, "id" : "obj-19", "numinlets" : 2, "patching_rect" : [ 343.15625, 235.0, 55.0, 18.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "message", "text" : "xfade $1", "outlettype" : [ "" ], "fontname" : "Arial", "fontsize" : 11.595187, "id" : "obj-21", "numinlets" : 2, "patching_rect" : [ 286.737488, 235.0, 55.0, 18.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "newobj", "text" : "jit.xfade", "outlettype" : [ "jit_matrix", "" ], "fontname" : "Arial", "fontsize" : 11.595187, "id" : "obj-22", "numinlets" : 2, "patching_rect" : [ 50.0, 259.0, 50.0, 20.0 ], "numoutlets" : 2 } } , { "box" : { "maxclass" : "flonum", "outlettype" : [ "float", "bang" ], "fontname" : "Arial", "triscale" : 0.9, "fontsize" : 11.595187, "id" : "obj-23", "numinlets" : 1, "patching_rect" : [ 327.668762, 113.0, 50.0, 20.0 ], "numoutlets" : 2 } } , { "box" : { "maxclass" : "message", "text" : "rate $1", "outlettype" : [ "" ], "fontname" : "Arial", "fontsize" : 11.595187, "id" : "obj-24", "numinlets" : 2, "patching_rect" : [ 327.668762, 138.0, 47.0, 18.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "message", "text" : "read", "outlettype" : [ "" ], "fontname" : "Arial", "fontsize" : 11.595187, "id" : "obj-25", "numinlets" : 2, "patching_rect" : [ 257.975006, 138.0, 34.0, 18.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "newobj", "text" : "jit.qt.movie 320 240", "outlettype" : [ "jit_matrix", "" ], "fontname" : "Arial", "fontsize" : 11.595187, "id" : "obj-26", "numinlets" : 1, "patching_rect" : [ 257.975006, 176.0, 111.0, 20.0 ], "numoutlets" : 2 } } , { "box" : { "maxclass" : "flonum", "outlettype" : [ "float", "bang" ], "fontname" : "Arial", "triscale" : 0.9, "fontsize" : 11.595187, "id" : "obj-27", "numinlets" : 1, "patching_rect" : [ 202.981247, 113.0, 50.0, 20.0 ], "numoutlets" : 2 } } , { "box" : { "maxclass" : "message", "text" : "rate $1", "outlettype" : [ "" ], "fontname" : "Arial", "fontsize" : 11.595187, "id" : "obj-28", "numinlets" : 2, "patching_rect" : [ 202.981247, 138.0, 47.0, 18.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "message", "text" : "read", "outlettype" : [ "" ], "fontname" : "Arial", "fontsize" : 11.595187, "id" : "obj-29", "numinlets" : 2, "patching_rect" : [ 133.287491, 138.0, 34.0, 18.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "flonum", "outlettype" : [ "float", "bang" ], "minimum" : 0.5, "fontname" : "Arial", "triscale" : 0.9, "fontsize" : 11.595187, "id" : "obj-30", "numinlets" : 1, "patching_rect" : [ 94.0, 113.0, 50.0, 20.0 ], "numoutlets" : 2 } } , { "box" : { "maxclass" : "toggle", "outlettype" : [ "int" ], "id" : "obj-31", "numinlets" : 1, "patching_rect" : [ 50.0, 113.0, 20.0, 20.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "newobj", "text" : "qmetro 30", "outlettype" : [ "bang" ], "fontname" : "Arial", "fontsize" : 11.595187, "id" : "obj-32", "numinlets" : 2, "patching_rect" : [ 50.0, 137.0, 63.0, 20.0 ], "numoutlets" : 1 } } , { "box" : { "maxclass" : "newobj", "text" : "jit.qt.movie 320 240", "outlettype" : [ "jit_matrix", "" ], "fontname" : "Arial", "fontsize" : 11.595187, "id" : "obj-33", "numinlets" : 1, "patching_rect" : [ 50.0, 176.0, 111.0, 20.0 ], "numoutlets" : 2 } } , { "box" : { "maxclass" : "jit.pwindow", "outlettype" : [ "", "" ], "presentation_rect" : [ 149.0, 31.0, 542.0, 494.0 ], "id" : "obj-17", "background" : 1, "numinlets" : 1, "patching_rect" : [ 50.0, 321.0, 320.0, 240.0 ], "presentation" : 1, "numoutlets" : 2 } } ], "lines" : [ { "patchline" : { "source" : [ "obj-1", 0 ], "destination" : [ "obj-21", 0 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-23", 0 ], "destination" : [ "obj-24", 0 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-32", 0 ], "destination" : [ "obj-26", 0 ], "hidden" : 0, "midpoints" : [ 59.5, 170.0, 267.475006, 170.0 ] } } , { "patchline" : { "source" : [ "obj-25", 0 ], "destination" : [ "obj-26", 0 ], "hidden" : 0, "midpoints" : [ 267.475006, 164.0, 267.475006, 164.0 ] } } , { "patchline" : { "source" : [ "obj-24", 0 ], "destination" : [ "obj-26", 0 ], "hidden" : 0, "midpoints" : [ 337.168762, 164.0, 267.475006, 164.0 ] } } , { "patchline" : { "source" : [ "obj-14", 0 ], "destination" : [ "obj-26", 0 ], "hidden" : 0, "midpoints" : [ 302.875, 164.0, 267.475006, 164.0 ] } } , { "patchline" : { "source" : [ "obj-27", 0 ], "destination" : [ "obj-28", 0 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-22", 1 ], "destination" : [ "obj-18", 0 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-26", 0 ], "destination" : [ "obj-22", 1 ], "hidden" : 0, "midpoints" : [ 267.475006, 204.0, 90.5, 204.0 ] } } , { "patchline" : { "source" : [ "obj-30", 0 ], "destination" : [ "obj-32", 1 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-17", 0 ], "destination" : [ "obj-13", 0 ], "hidden" : 0, "midpoints" : [ 59.5, 573.0, 375.0, 573.0, 375.0, 525.0, 389.5, 525.0 ] } } , { "patchline" : { "source" : [ "obj-21", 0 ], "destination" : [ "obj-22", 0 ], "hidden" : 0, "midpoints" : [ 296.237488, 256.0, 59.5, 256.0 ] } } , { "patchline" : { "source" : [ "obj-19", 0 ], "destination" : [ "obj-22", 0 ], "hidden" : 0, "midpoints" : [ 352.65625, 256.0, 59.5, 256.0 ] } } , { "patchline" : { "source" : [ "obj-33", 0 ], "destination" : [ "obj-22", 0 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-28", 0 ], "destination" : [ "obj-33", 0 ], "hidden" : 0, "midpoints" : [ 212.481247, 164.0, 59.5, 164.0 ] } } , { "patchline" : { "source" : [ "obj-29", 0 ], "destination" : [ "obj-33", 0 ], "hidden" : 0, "midpoints" : [ 142.787491, 164.0, 59.5, 164.0 ] } } , { "patchline" : { "source" : [ "obj-15", 0 ], "destination" : [ "obj-33", 0 ], "hidden" : 0, "midpoints" : [ 177.081253, 164.0, 59.5, 164.0 ] } } , { "patchline" : { "source" : [ "obj-32", 0 ], "destination" : [ "obj-33", 0 ], "hidden" : 0, "midpoints" : [ 59.5, 169.0, 59.5, 169.0 ] } } , { "patchline" : { "source" : [ "obj-31", 0 ], "destination" : [ "obj-32", 0 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-22", 0 ], "destination" : [ "obj-17", 0 ], "hidden" : 0, "midpoints" : [ ] } } , { "patchline" : { "source" : [ "obj-3", 0 ], "destination" : [ "obj-1", 0 ], "hidden" : 0, "midpoints" : [ ] } } ] }
- Login to post comments