Category: Uncategorized

Temboo Location

location: 77 Greenwood Circle Womleysburg, PA
latitude: 40.255775
longitude: -76.90538

// More examples & getting started tutorials can be found at:
// https://temboo.com/processing
// Import the Temboo library core and appropriate Choreos
import com.temboo.core.*;
import com.temboo.Library.Google.Geocoding.*;

// Create a session using your Temboo account application details
// If you don't have a Temboo account, sign up here:
// http://temboo.com/signup
// If you do have a Temboo account, find your application details here:
// http://temboo.com/account/applications
TembooSession session = new TembooSession("salexy", "myFirstApp", "111dc69fd5864a3e95ef1ed410610654");

// Set up some global variables
String location = "77 Greenwood Circle Womleysburg, PA";
float latitude, longitude;

void setup() {
// Run the GeocodeByAddress Choreo function
runGeocodeByAddressChoreo();
}

void runGeocodeByAddressChoreo() {
// Create the Choreo object using your Temboo session
GeocodeByAddress geocodeByAddressChoreo = new GeocodeByAddress(session);

// Set inputs
geocodeByAddressChoreo.setAddress(location);

// Run the Choreo and store the results
GeocodeByAddressResultSet geocodeByAddressResults = geocodeByAddressChoreo.run();

// Save latitude and longitude as floats
latitude = float(geocodeByAddressResults.getLatitude());
longitude = float(geocodeByAddressResults.getLongitude());

// Print latitude and longitude
println("location: " + location);
println("latitude: " + latitude);
println("longitude: " + longitude);
}

Dc Motor

DC Motor

photo 1

DC Motor FRITZ

/*     -----------------------------------------------------------
 *     |  Arduino Experimentation Kit Example Code               |
 *     |  CIRC-03 .: Spin Motor Spin :. (Transistor and Motor)   |
 *     -----------------------------------------------------------
 * 
 * The Arduinos pins are great for driving LEDs however if you hook 
 * up something that requires more power you will quickly break them.
 * To control bigger items we need the help of a transistor. 
 * Here we will use a transistor to control a small toy motor
 * 
 * http://tinyurl.com/d4wht7
 *
 */

int motorPin = 9;  // define the pin the motor is connected to
                   // (if you use pin 9,10,11 or 3you can also control speed)

/*
 * setup() - this function runs once when you turn your Arduino on
 * We set the motors pin to be an output (turning the pin high (+5v) or low (ground) (-))
 * rather than an input (checking whether a pin is high or low)
 */
void setup()
{
 pinMode(motorPin, OUTPUT); 
}


/*
 * loop() - this function will start after setup finishes and then repeat
 * we call a function called motorOnThenOff()
 */

void loop()                     // run over and over again
{
 motorOnThenOff();
 //motorOnThenOffWithSpeed();
 //motorAcceleration();
}

/*
 * motorOnThenOff() - turns motor on then off 
 * (notice this code is identical to the code we used for
 * the blinking LED)
 */
void motorOnThenOff(){
  int onTime = 2500;  //the number of milliseconds for the motor to turn on for
  int offTime = 1000; //the number of milliseconds for the motor to turn off for
  
  digitalWrite(motorPin, HIGH); // turns the motor On
  delay(onTime);                // waits for onTime milliseconds
  digitalWrite(motorPin, LOW);  // turns the motor Off
  delay(offTime);               // waits for offTime milliseconds
}

/*
 * motorOnThenOffWithSpeed() - turns motor on then off but uses speed values as well 
 * (notice this code is identical to the code we used for
 * the blinking LED)
 */
void motorOnThenOffWithSpeed(){
  
  int onSpeed = 200;  // a number between 0 (stopped) and 255 (full speed) 
  int onTime = 2500;  //the number of milliseconds for the motor to turn on for
  
  int offSpeed = 50;  // a number between 0 (stopped) and 255 (full speed) 
  int offTime = 1000; //the number of milliseconds for the motor to turn off for
  
  analogWrite(motorPin, onSpeed);   // turns the motor On
  delay(onTime);                    // waits for onTime milliseconds
  analogWrite(motorPin, offSpeed);  // turns the motor Off
  delay(offTime);                   // waits for offTime milliseconds
}

/*
 * motorAcceleration() - accelerates the motor to full speed then
 * back down to zero
*/
void motorAcceleration(){
  int delayTime = 50; //milliseconds between each speed step
  
  //Accelerates the motor
  for(int i = 0; i < 256; i++){ //goes through each speed from 0 to 255
    analogWrite(motorPin, i);   //sets the new speed
    delay(delayTime);           // waits for delayTime milliseconds
  }
  
  //Decelerates the motor
  for(int i = 255; i >= 0; i--){ //goes through each speed from 255 to 0
    analogWrite(motorPin, i);   //sets the new speed
    delay(delayTime);           // waits for delayTime milliseconds
  }
}

Circuits 3 and 4

 

Working with Motors:
Circuit 3: Toy Motor

Circuit 3 diagram Circuit 3 diagram

 

Circuit 3 Circuit 3

Code:

/*     -----------------------------------------------------------
 *     |  Arduino Experimentation Kit Example Code               |
 *     |  CIRC-03 .: Spin Motor Spin :. (Transistor and Motor)   |
 *     -----------------------------------------------------------
 * 
 * The Arduinos pins are great for driving LEDs however if you hook 
 * up something that requires more power you will quickly break them.
 * To control bigger items we need the help of a transistor. 
 * Here we will use a transistor to control a small toy motor
 * 
 * http://tinyurl.com/d4wht7
 *
 */

int motorPin = 9;  // define the pin the motor is connected to
                   // (if you use pin 9,10,11 or 3you can also control speed)

/*
 * setup() - this function runs once when you turn your Arduino on
 * We set the motors pin to be an output (turning the pin high (+5v) or low (ground) (-))
 * rather than an input (checking whether a pin is high or low)
 */
void setup()
{
 pinMode(motorPin, OUTPUT); 
}


/*
 * loop() - this function will start after setup finishes and then repeat
 * we call a function called motorOnThenOff()
 */

void loop()                     // run over and over again
{
 motorOnThenOff();
 //motorOnThenOffWithSpeed();
 //motorAcceleration();
}

/*
 * motorOnThenOff() - turns motor on then off 
 * (notice this code is identical to the code we used for
 * the blinking LED)
 */
void motorOnThenOff(){
  int onTime = 2500;  //the number of milliseconds for the motor to turn on for
  int offTime = 1000; //the number of milliseconds for the motor to turn off for
  
  digitalWrite(motorPin, HIGH); // turns the motor On
  delay(onTime);                // waits for onTime milliseconds
  digitalWrite(motorPin, LOW);  // turns the motor Off
  delay(offTime);               // waits for offTime milliseconds
}

/*
 * motorOnThenOffWithSpeed() - turns motor on then off but uses speed values as well 
 * (notice this code is identical to the code we used for
 * the blinking LED)
 */
void motorOnThenOffWithSpeed(){
  
  int onSpeed = 200;  // a number between 0 (stopped) and 255 (full speed) 
  int onTime = 2500;  //the number of milliseconds for the motor to turn on for
  
  int offSpeed = 50;  // a number between 0 (stopped) and 255 (full speed) 
  int offTime = 1000; //the number of milliseconds for the motor to turn off for
  
  analogWrite(motorPin, onSpeed);   // turns the motor On
  delay(onTime);                    // waits for onTime milliseconds
  analogWrite(motorPin, offSpeed);  // turns the motor Off
  delay(offTime);                   // waits for offTime milliseconds
}

/*
 * motorAcceleration() - accelerates the motor to full speed then
 * back down to zero
*/
void motorAcceleration(){
  int delayTime = 50; //milliseconds between each speed step
  
  //Accelerates the motor
  for(int i = 0; i < 256; i++){ //goes through each speed from 0 to 255     analogWrite(motorPin, i);   //sets the new speed     delay(delayTime);           // waits for delayTime milliseconds   }      //Decelerates the motor   for(int i = 255; i >= 0; i--){ //goes through each speed from 255 to 0
    analogWrite(motorPin, i);   //sets the new speed
    delay(delayTime);           // waits for delayTime milliseconds
  }
}



Circuit 4: Servo

Circuit 4 diagram Circuit 4 diagram

 

Circuit 4 Circuit 4

Code:

// Sweep
// by BARRAGAN  

#include  
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
 
void loop() 
{ 
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees    {                                  // in steps of 1 degree      myservo.write(pos);              // tell servo to go to position in variable 'pos'      delay(15);                       // waits 15ms for the servo to reach the position    }    for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
} 



DC Motor

20141103_222817

CIRC03

 


/*     -----------------------------------------------------------
 *     |  Arduino Experimentation Kit Example Code               |
 *     |  CIRC-03 .: Spin Motor Spin :. (Transistor and Motor)   |
 *     -----------------------------------------------------------
 * 
 * The Arduinos pins are great for driving LEDs however if you hook 
 * up something that requires more power you will quickly break them.
 * To control bigger items we need the help of a transistor. 
 * Here we will use a transistor to control a small toy motor
 * 
 * http://tinyurl.com/d4wht7
 *
 */
 
int motorPin = 9;  // define the pin the motor is connected to
                   // (if you use pin 9,10,11 or 3you can also control speed)
 
/*
 * setup() - this function runs once when you turn your Arduino on
 * We set the motors pin to be an output (turning the pin high (+5v) or low (ground) (-))
 * rather than an input (checking whether a pin is high or low)
 */
void setup()
{
 pinMode(motorPin, OUTPUT); 
}
 
 
/*
 * loop() - this function will start after setup finishes and then repeat
 * we call a function called motorOnThenOff()
 */
 
void loop()                     // run over and over again
{
 motorOnThenOff();
 //motorOnThenOffWithSpeed();
 //motorAcceleration();
}
 
/*
 * motorOnThenOff() - turns motor on then off 
 * (notice this code is identical to the code we used for
 * the blinking LED)
 */
void motorOnThenOff(){
  int onTime = 2500;  //the number of milliseconds for the motor to turn on for
  int offTime = 1000; //the number of milliseconds for the motor to turn off for
 
  digitalWrite(motorPin, HIGH); // turns the motor On
  delay(onTime);                // waits for onTime milliseconds
  digitalWrite(motorPin, LOW);  // turns the motor Off
  delay(offTime);               // waits for offTime milliseconds
}
 
/*
 * motorOnThenOffWithSpeed() - turns motor on then off but uses speed values as well 
 * (notice this code is identical to the code we used for
 * the blinking LED)
 */
void motorOnThenOffWithSpeed(){
 
  int onSpeed = 200;  // a number between 0 (stopped) and 255 (full speed) 
  int onTime = 2500;  //the number of milliseconds for the motor to turn on for
 
  int offSpeed = 50;  // a number between 0 (stopped) and 255 (full speed) 
  int offTime = 1000; //the number of milliseconds for the motor to turn off for
 
  analogWrite(motorPin, onSpeed);   // turns the motor On
  delay(onTime);                    // waits for onTime milliseconds
  analogWrite(motorPin, offSpeed);  // turns the motor Off
  delay(offTime);                   // waits for offTime milliseconds
}
 
/*
 * motorAcceleration() - accelerates the motor to full speed then
 * back down to zero
*/
void motorAcceleration(){
  int delayTime = 50; //milliseconds between each speed step
 
  //Accelerates the motor
  for(int i = 0; i < 256; i++){ //goes through each speed from 0 to 255     analogWrite(motorPin, i);   //sets the new speed     delay(delayTime);           // waits for delayTime milliseconds   }      //Decelerates the motor   for(int i = 255; i >= 0; i--){ //goes through each speed from 255 to 0
    analogWrite(motorPin, i);   //sets the new speed
    delay(delayTime);           // waits for delayTime milliseconds
  }
}

Circ 3 and 4

Circ -03: Motor

Circuit Picture:

circ03_bb

Youtube:

Code:

/*     -----------------------------------------------------------
 *     |  Arduino Experimentation Kit Example Code               |
  *     |  CIRC-03 .: Spin Motor Spin :. (Transistor and Motor)   |
  *     -----------------------------------------------------------
 * 
  * The Arduinos pins are great for driving LEDs however if you hook 
  * up something that requires more power you will quickly break them.
  * To control bigger items we need the help of a transistor. 
  * Here we will use a transistor to control a small toy motor
  * 
  * http://tinyurl.com/d4wht7
  *
  */

 int motorPin = 9;  // define the pin the motor is connected to
                    // (if you use pin 9,10,11 or 3you can also control speed)

 /*
  * setup() - this function runs once when you turn your Arduino on
  * We set the motors pin to be an output (turning the pin high (+5v) or low (ground) (-))
  * rather than an input (checking whether a pin is high or low)
  */
 void setup()
 {
  pinMode(motorPin, OUTPUT); 
 }


 /*
  * loop() - this function will start after setup finishes and then repeat
  * we call a function called motorOnThenOff()
  */

 void loop()                     // run over and over again
 {
  motorOnThenOff();
  //motorOnThenOffWithSpeed();
  //motorAcceleration();
 }

 /*
  * motorOnThenOff() - turns motor on then off 
  * (notice this code is identical to the code we used for
  * the blinking LED)
  */
 void motorOnThenOff(){
   int onTime = 2500;  //the number of milliseconds for the motor to turn on for
   int offTime = 1000; //the number of milliseconds for the motor to turn off for
   
   digitalWrite(motorPin, HIGH); // turns the motor On
   delay(onTime);                // waits for onTime milliseconds
   digitalWrite(motorPin, LOW);  // turns the motor Off
   delay(offTime);               // waits for offTime milliseconds
 }

 /*
  * motorOnThenOffWithSpeed() - turns motor on then off but uses speed values as well 
  * (notice this code is identical to the code we used for
  * the blinking LED)
  */
 void motorOnThenOffWithSpeed(){
   
   int onSpeed = 200;  // a number between 0 (stopped) and 255 (full speed) 
   int onTime = 2500;  //the number of milliseconds for the motor to turn on for
   
   int offSpeed = 50;  // a number between 0 (stopped) and 255 (full speed) 
   int offTime = 1000; //the number of milliseconds for the motor to turn off for
   
   analogWrite(motorPin, onSpeed);   // turns the motor On
   delay(onTime);                    // waits for onTime milliseconds
   analogWrite(motorPin, offSpeed);  // turns the motor Off
   delay(offTime);                   // waits for offTime milliseconds
 }

 /*
  * motorAcceleration() - accelerates the motor to full speed then
  * back down to zero
 */
 void motorAcceleration(){
   int delayTime = 50; //milliseconds between each speed step
   
   //Accelerates the motor
   for(int i = 0; i < 256; i++){ //goes through each speed from 0 to 255
     analogWrite(motorPin, i);   //sets the new speed
     delay(delayTime);           // waits for delayTime milliseconds
   }
   
   //Decelerates the motor
   for(int i = 255; i >= 0; i--){ //goes through each speed from 255 to 0
     analogWrite(motorPin, i);   //sets the new speed
     delay(delayTime);           // waits for delayTime milliseconds
   }
 }

Circ – 04: The Micro Servo

Circuit Diagram:

circ04_bb

Youtube:

Code:

// Sweep
 // by BARRAGAN  

 #include  
  
 Servo myservo;  // create servo object to control a servo 
                 // a maximum of eight servo objects can be created 
  
 int pos = 0;    // variable to store the servo position 
  
 void setup() 
 { 
   myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
 } 
  
  
 void loop() 
 { 
   for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
   {                                  // in steps of 1 degree 
     myservo.write(pos);              // tell servo to go to position in variable 'pos' 
     delay(15);                       // waits 15ms for the servo to reach the position 
   } 
   for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
   {                                
     myservo.write(pos);              // tell servo to go to position in variable 'pos' 
     delay(15);                       // waits 15ms for the servo to reach the position 
   } 
 }

Assignment 10: Temperature Sensor

IMG_1089

Thermistor_bb

int temperaturePin = 0;

void setup()
{
  Serial.begin(9600);  //Start the serial connection with the copmuter
                       //to view the result open the serial monitor 
                       //last button beneath the file bar (looks like a box with an antenae)
}
 
void loop()                     // run over and over again
{
 float temperature = getVoltage(temperaturePin);  //getting the voltage reading from the tem
                    //perature sensor
 temperature = (temperature - .5) * 100;          //converting from 10 mv per degree wit 500
                    // mV offset
                                                  //to degrees ((volatge - 500mV) times 100)
 Serial.println(temperature);                     //printing the result
 delay(1000);                                     //waiting a second
}

/*
 * getVoltage() - returns the voltage on the analog input defined by
 * pin
 */
float getVoltage(int pin){
 return (analogRead(pin) * .004882814); //converting from a 0 to 1023 digital range
                                        // to 0 to 5 volts (each 1 reading equals ~ 5 milliv
                    //olts
}

 

Sensors: Thunder

Thunder

I was working on a site fairly recently where a nearby building was using an old siren as a warning. The kind that served as warnings for the Blitzkrieg. This got me thinking about warnings, and I ended up wanting to work with that same sound. Thunder is, in concept, a simulator for someone reminiscing about the blitz. It consists of three sensors: one proximity sensor on the headphones, and 2 light sensors on the board. Triggereing all of them will cause a recording of  blitz sirens to play. Removing your hands or taking off the headphones causes the audio to stop.

//video here

In this video, the headphones are unplugged for demonstration reasons. Originally I wanted to have it so that the user’s hands would have to cover their ears, but this led to complications. The act of physically placing your hands in a certain place functions as giving an entry and exit to the space of memory.

IMG_1074

the full rig

IMG_1081

the two green squares are light sensors, and the purple/white cable set leads to  the headphone sensor. the other leads nowhere and does nothing.

IMG_1082

Arduino Code. Modified to return a yes/no response

int sv0 = 0;  // variable to store the value coming from the sensors
int sv1 = 0;
int sv2 = 0; 
int req = 400;
 
void setup() {
  Serial.begin(9600);  // initialize serial communications    
}
 
void loop() {
 
  // Read the value from the sensors:
  sv0 = analogRead (A0); 
  sv1 = analogRead (A1);  
  sv2 = analogRead (A2);  
 
  //Serial.print(sv0);
  //Serial.print(" : ");
  //Serial.print(sv1);
  //Serial.print(" : ");
  //Serial.println(sv2);
  if((sv0 < req) && (sv1 < req) && (sv2 < req)){
    Serial.println ("A");
  } else {
    Serial.println ("B");
  }
  delay (50);   // wait a fraction of a second, to be polite
}

Processing Code

// Processing program to handle audio playing
 
// Import the Serial library and create a Serial port handler
import processing.serial.*;
Serial myPort;   
 
import ddf.minim.*; 
Minim minim;
AudioPlayer player; 
 
int valueA;  // Sensor Value A
int valueB;  // Sensor Value B
Boolean running = false;
 
//------------------------------------
void setup() {
  size(1024, 200);
 
  // List my available serial ports
  int nPorts = Serial.list().length; 
  for (int i=0; i &lt; nPorts; i++) {
    println("Port " + i + ": " + Serial.list()[i]);
  } 
 
  // Choose which serial port to fetch data from. 
  // IMPORTANT: This depends on your computer!!!
  // Read the list of ports printed by the code above,
  // and try choosing the one like /dev/cu.usbmodem1411
  // On my laptop, I'm using port #4, but yours may differ.
  String portName = Serial.list()[5]; 
  myPort = new Serial(this, portName, 9600);
  serialChars = new ArrayList();
  
  minim = new Minim(this);
  player = minim.loadFile("AirRaidSirens1.wav");
  
}
 
//------------------------------------
void draw() {
 
  // Process the serial data. This acquires freshest values. 
  processSerial();
 
  background (150);  
 
}
 
 
//---------------------------------------------------------------
// The processSerial() function acquires serial data byte-by-byte, 
// as it is received, and when it is properly captured, modifies
// the appropriate global variable. 
// You won't have to change anything unless you want to add additional sensors. 

ArrayList serialChars;      // Temporary storage for received serial data
int whichValueToAccum = 0;  // Which piece of data am I currently collecting? 
boolean bJustBuilt = false; // Did I just finish collecting a datum?
 
void processSerial() {
 
  while (myPort.available () &gt; 0) {
    char aChar = (char) myPort.read();
 
    // checks whether all sensors are currently triggered or not.
    if (aChar == 'A' &amp;&amp; running == false) {
      running = true;
      player.play();
      println("playing...");
    } else if (aChar == 'B' &amp;&amp; running == true) {
      running = false;
      println("stopping");
      player.pause();
      player.rewind();
    }
  }
}

 

The Experience Generator

For my project, I wanted to process my user’s interactions into actual control of their desktop. I utilize the arduino’s serial connections and java’s ability to control your keyboard and mouse to turn a big red button and a sliber bar into an “Interactive Reddit Experience Generator.” By Translating the slider movement to be a scaled value from “Mundane and Probably SFW” to “Different and Probably NSFW” I allow the user to dictate the browsing experience of the current session with the click of a button. The Decisions on what is “Different” or “Mundane” is currently up to my personal taste but I would like to write an algorithm which automatically does this for me.

Here are a few stills of what the experience generator can throw out.

Snap 2014-10-29 at 18.15.37

Snap 2014-10-29 at 18.16.16

Snap 2014-10-29 at 18.16.56

Here is my Arduino and Processing Code (The Arduino code is about the same as the example code, while the processing code uses quite a few java libraries.”

Special thanks to Alvin Alexander at alvinalexander.com for a well documented java typing example!

// This Processing program reads serial data for two sensors,
// presumably digitized by and transmitted from an Arduino. 
// It displays two rectangles whose widths are proportional
// to the values 0-1023 received from the Arduino.
 
// Import the Serial library and create a Serial port handler
import processing.serial.*;
import java.awt.Desktop;
import java.net.URI;
Serial myPort;   

import java.awt.Robot;
import java.awt.AWTException;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

Robot rob;

boolean run = false;
int timeHit = 0;

ArrayList<Tuple> rankings;

int listLength;
 
// Hey you! Use these variables to do something interesting. 
// If you captured them with analog sensors on the arduino, 
// They're probably in the range from 0 ... 1023:
int valueA;  // Sensor Value A
int valueB;  // Sensor Value B
 
//------------------------------------
void setup() { 
  size(50,50);
  rankings = new ArrayList<Tuple>();
  initList();
  
  //Set up Bot to move mouse
  try {
  rob = new Robot();
  }
  catch (AWTException e) {
    e.printStackTrace();
  }
 
  // List my available serial ports
  int nPorts = Serial.list().length; 
  for (int i=0; i < nPorts; i++) {
    println("Port " + i + ": " + Serial.list()[i]);
  } 
 
  // Choose which serial port to fetch data from. 
  // IMPORTANT: This depends on your computer!!!
  // Read the list of ports printed by the code above,
  // and try choosing the one like /dev/cu.usbmodem1411
  // On my laptop, I'm using port #4, but yours may differ.
  String portName = Serial.list()[0]; 
  myPort = new Serial(this, portName, 9600);
  serialChars = new ArrayList();
  rob.delay(300); 
}
 
//------------------------------------
void draw() {
 
  // Process the serial data. This acquires freshest values. 
  processSerial();

  if ((valueB > 0) && (!run) && (millis() - timeHit > 50)) {
      run = true;
      timeHit = millis();
      runWindow();
      delay(300);
  }
  if ((run) && valueB > 0) {
      findSub();
      rect(0,0,width,height);
  }
}
 
ArrayList serialChars;      // Temporary storage for received serial data
int whichValueToAccum = 0;  // Which piece of data am I currently collecting? 
boolean bJustBuilt = false; // Did I just finish collecting a datum?
 
void processSerial() {
 
  while (myPort.available () > 0) {
    char aChar = (char) myPort.read();
 
    // You'll need to add a block like one of these 
    // if you want to add a 3rd sensor:
    if (aChar == 'A') {
      bJustBuilt = false;
      whichValueToAccum = 0;
    } else if (aChar == 'B') {
      bJustBuilt = false;
      whichValueToAccum = 1;
    } else if (((aChar == 13) || (aChar == 10)) && (!bJustBuilt)) {
      // If we just received a return or newline character, build the number: 
      int accum = 0; 
      int nChars = serialChars.size(); 
      for (int i=0; i < nChars; i++) { 
        int n = (nChars - i) - 1; 
        int aDigit = ((Integer)(serialChars.get(i))).intValue(); 
        accum += aDigit * (int)(pow(10, n));
      }
 
      // Set the global variable to the number we captured.
      // You'll need to add another block like one of these 
      // if you want to add a 3rd sensor:
      if (whichValueToAccum == 0) {
        valueA = accum;
        // println ("A = " + valueA);
      } else if (whichValueToAccum == 1) {
        valueB = accum;
        // println ("B = " + valueB);
      }
 
      // Now clear the accumulator
      serialChars.clear();
      bJustBuilt = true;
 
    } else if ((aChar >= 48) && (aChar <= 57)) {
      // If the char is between '0' and '9', save it.
      int aDigit = (int)(aChar - '0'); 
      serialChars.add(aDigit);
    }
  }
}

void runWindow() {
    if(Desktop.isDesktopSupported()) {
      try {
          Desktop.getDesktop().browse(new URI("http://www.google.com"));
      } catch (Exception e) {
        println("Oh no");
      }
   }
}

void initList() {
  //Initialize List (Yes it's ugly but it was a 
//quick conversion from python)
rankings.add(new Tuple("pics", -1));
rankings.add(new Tuple("funny", 0));
rankings.add(new Tuple("aww", 0));
rankings.add(new Tuple("cats", 0));
rankings.add(new Tuple("dIY", 0));
rankings.add(new Tuple("todayilearned", 1));
rankings.add(new Tuple("videos", 1));
rankings.add(new Tuple("gaming", 1));
rankings.add(new Tuple("politics", 1));
rankings.add(new Tuple("technology", 1));
rankings.add(new Tuple("space", 1));
rankings.add(new Tuple("bitcoin", 1));
rankings.add(new Tuple("art", 1));
rankings.add(new Tuple("foodporn", 1));
rankings.add(new Tuple("blep", 1));
rankings.add(new Tuple("askreddit", 2));
rankings.add(new Tuple("atheism", 2));
rankings.add(new Tuple("imgoingtohellforthis", 2));
rankings.add(new Tuple("gentlemanboners", 2));
rankings.add(new Tuple("tattoos", 2));
rankings.add(new Tuple("nosleep", 2));
rankings.add(new Tuple("malefashionadvice", 2));
rankings.add(new Tuple("woodworking", 2));
rankings.add(new Tuple("christianity", 2));
rankings.add(new Tuple("nononono", 2));
rankings.add(new Tuple("gaybros", 2.3));
rankings.add(new Tuple("tinder", 2.5));
rankings.add(new Tuple("microgrowery", 2.7));
rankings.add(new Tuple("trees", 3));
rankings.add(new Tuple("relationships", 3));
rankings.add(new Tuple("shittynosleep", 3));
rankings.add(new Tuple("lifehacks", 3));
rankings.add(new Tuple("girlsinyogapants", 3));
rankings.add(new Tuple("politota", 3));
rankings.add(new Tuple("forwardsfromgrandma", 3.2));
rankings.add(new Tuple("ebola", 3.5));
rankings.add(new Tuple("WTF", 4));
rankings.add(new Tuple("nsfw", 4));
rankings.add(new Tuple("realgirls", 4));
rankings.add(new Tuple("ladyboners", 4));
rankings.add(new Tuple("exmormon", 4));
rankings.add(new Tuple("odd", 4));
rankings.add(new Tuple("nofap", 4));
rankings.add(new Tuple("swoleacceptance", 4));
rankings.add(new Tuple("colanders", 4));
rankings.add(new Tuple("4chan", 5));
rankings.add(new Tuple("nsfw_gif", 5));
rankings.add(new Tuple("ass", 5));
rankings.add(new Tuple("youtubehaiku", 5));
rankings.add(new Tuple("asstastic", 5));
rankings.add(new Tuple("humanporn", 5));
rankings.add(new Tuple("classic4chan", 5));
rankings.add(new Tuple("milf", 6));
rankings.add(new Tuple("creepypms", 6));
rankings.add(new Tuple("mensrights", 6));
rankings.add(new Tuple("translucent_porn", 6));
rankings.add(new Tuple("fiftyfifty", 7));
rankings.add(new Tuple("futanari", 7));
rankings.add(new Tuple("watchpeopledie", 9));
rankings.add(new Tuple("spacedicks", 10));

listLength = rankings.size();
}

void leftClick() {
    rob.mousePress(InputEvent.BUTTON1_MASK);
    rob.delay(200);
    rob.mouseRelease(InputEvent.BUTTON1_MASK);
    rob.delay(200);
    }

void type( String s) {
  rob.keyPress(KeyEvent.VK_CONTROL);
  rob.keyPress(KeyEvent.VK_L);
  
  rob.keyRelease(KeyEvent.VK_CONTROL);
  rob.keyRelease(KeyEvent.VK_L);
  byte[] bytes = s.getBytes();
  for (byte b : bytes)
  {
    int code = b;
    if (code > 96 && code < 123){
      code = code - 32;
      rob.delay(100);
      rob.keyPress(code);
      rob.keyRelease(code);
    }
    else if (code == 46) {
      rob.keyPress(KeyEvent.VK_PERIOD);
      rob.keyRelease(KeyEvent.VK_PERIOD);
    }
    else if (code == 47) {
      rob.keyPress(KeyEvent.VK_SLASH);
      rob.keyRelease(KeyEvent.VK_SLASH);
    }
    else if (code == 95) {

    }
      
   
  }
  rob.keyPress(KeyEvent.VK_ENTER);
  rob.keyRelease(KeyEvent.VK_ENTER);
}

class Tuple {
  public String value;
  public float rating;
  public Tuple(String v, float r) {
    value = v;
    rating = r;
  }
}

void findSub() {
  delay(100);
  int i = (int)map(valueA, 0, 1000, 0, listLength-2) ;
  String sub = rankings.get(i).value;
  String url = String.format("reddit.com/r/%s",sub);
  type(url);
}

Here’s the Arduino code

int sensorValue0 = 0;  // variable to store the value coming from the sensor
int sensorValue1 = 0;  // variable to store the value coming from the other sensor
 
void setup() {
  Serial.begin(9600);  // initialize serial communications    
}
 
void loop() {
 
  // Read the value from the sensor(s):
  sensorValue0 = analogRead (A0);  // reads value from Analog input 0
  sensorValue1 = analogRead (A1);  // reads value from Analog input 1    
 
  Serial.print ("A"); 
  Serial.println (sensorValue0); 
  Serial.print ("B"); 
  Serial.println (sensorValue1);  
 
  delay (50);   // wait a fraction of a second, to be polite
}

Here’s a fritzing diagram of the circuit I used.

ExperienceGenerator

OFace

For this assignment, I decided to use the squeezing sensor to work with my program. I wanted to create an image of a mouth that oped wider and wider the harder you squeezed the sensor thus resembling the sensual orgasmic face. I thought about using the twisting sensor to resemble the nipple however, that sensor was more of an on and off sensor that wouldn’t need constant human touch to activate it. I need more help with a more interactive/ gaming/ goal orient visual experience. One thought I had was to have a timer going to see if the individual to “stimulate” at a consistent temperature for a certain amount of time. However, that seems to bland as well. I do not have documentation because I have forgotten to take out my USB cord from my suitcase every single time I leave home for the day.

<

import processing.serial.*;
Serial myPort;

// Hey you! Use these variables to do something interesting.
// If you captured them with analog sensors on the arduino,
// They’re probably in the range from 0 … 1023:
int valueA; // Sensor Value A

float runningAvgA;

//————————————
void setup() {
size(400, 400);
runningAvgA = 0;

// List my available serial ports
int nPorts = Serial.list().length;
for (int i=0; i < nPorts; i++) { println("Port " + i + ": " + Serial.list()[i]); } // Choose which serial port to fetch data from. // IMPORTANT: This depends on your computer!!! // Read the list of ports printed by the code above, // and try choosing the one like /dev/cu.usbmodem1411 // On my laptop, I'm using port #4, but yours may differ. String portName = Serial.list()[4]; myPort = new Serial(this, portName, 9600); serialChars = new ArrayList(); } //------------------------------------ void draw() { // Process the serial data. This acquires freshest values. processSerial(); strokeJoin (ROUND); runningAvgA = 0.95*runningAvgA + 0.05*valueA; background (200,100,100); float m = map(runningAvgA, 0,1000, 0, height); strokeWeight(20); stroke(255, 100, 100); ellipse(width/2, height/2, 200, m); fill (0); stroke(0); strokeWeight(1); ellipse (width/2, height/2, 200, m); } //--------------------------------------------------------------- // The processSerial() function acquires serial data byte-by-byte, // as it is received, and when it is properly captured, modifies // the appropriate global variable. // You won't have to change anything unless you want to add additional sensors. /* The (expected) received serial data should look something like this: A903 B412 A900 B409 A898 B406 A895 B404 A893 B404 ...etcetera. */ ArrayList serialChars; // Temporary storage for received serial data int whichValueToAccum = 0; // Which piece of data am I currently collecting? boolean bJustBuilt = false; // Did I just finish collecting a datum? void processSerial() { while (myPort.available () > 0) {
char aChar = (char) myPort.read();

// You’ll need to add a block like one of these
// if you want to add a 3rd sensor:
if (aChar == ‘A’) {
bJustBuilt = false;
whichValueToAccum = 0;
} else if (aChar == ‘B’) {
bJustBuilt = false;
whichValueToAccum = 1;
} else if (((aChar == 13) || (aChar == 10)) && (!bJustBuilt)) {
// If we just received a return or newline character, build the number:
int accum = 0;
int nChars = serialChars.size();
for (int i=0; i < nChars; i++) { int n = (nChars - i) - 1; int aDigit = ((Integer)(serialChars.get(i))).intValue(); accum += aDigit * (int)(pow(10, n)); } // Set the global variable to the number we captured. // You'll need to add another block like one of these // if you want to add a 3rd sensor: if (whichValueToAccum == 0) { valueA = accum; // println ("A = " + valueA); } // Now clear the accumulator serialChars.clear(); bJustBuilt = true; } else if ((aChar >48) && (aChar <57)) {
// If the char is between ‘0’ and ‘9’, save it.
int aDigit = (int)(aChar – ‘0’);
serialChars.add(aDigit);
}
}
}

Arduino Code

int sensorValue0 = 0; // variable to store the value coming from the sensor

void setup() {
Serial.begin(9600); // initialize serial communications
}

void loop() {

// Read the value from the sensor(s):
sensorValue0 = analogRead (A0); // reads value from Analog input 0

Serial.print (“A”);
Serial.println (sensorValue0);

delay (50); // wait a fraction of a second, to be polite
}