Lab 2: Input/Output

To Do 

Create another circuit or modify your existing circuit, this time using the Arduino to read your input and to affect your output.

void setup() {
pinMode(7, INPUT);
pinMode(11, OUTPUT);
}

void loop() {
if (digitalRead(7) == 1) {
digitalWrite(11, HIGH);
} else {
digitalWrite(11, LOW);
}}

 
 

This experience was frustrating because I was not familiar with the basic concepts of circuits. I am now glad that I can understand better how circuits works, especially the fact that they need to be connected to power and ground to be complete. For this project, I coded port 7 as an input and used a switch that would allow the circuit to be closed and open. I used alligator cables for practical purposes and added a resistor to transfer the right amount of electricity to the circuit. Then the current goes to the led light which is coded as an output, and the circuit ends with the resistor being connected to ground.

Lab 3: On/Off & In-Between 

const int ledPin = 6; // pin that the LED is attached to
int analogValue = 0; // value read from the pot
int brightness = 0;

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}

void loop() {
analogValue = analogRead(A0); // read the pot value
brightness = analogValue ;9600/4; //divide by 4 to fit in a byte
analogWrite(ledPin, brightness); // PWM the LED with the brightness value
Serial.println(brightness); // print the brightness value back to the serial monitor
}

 
 

To Do 

Create circuit that makes use of Analog inputs and outputs where the interaction centers anywhere except the hands. If you choose to use hands then try getting your hands on an analog sensor that is NOT a potentiometer.

int fsrAnalogPin = 0;
int LEDpin = 6;
int fsrReading;
int LEDbrightness;

void setup(void) {
Serial.begin(9600);
pinMode(6, OUTPUT);
}

void loop(void) {
fsrReading = analogRead(fsrAnalogPin);
Serial.print("Analog reading = ");
Serial.println(fsrReading);

LEDbrightness = map(fsrReading, 0, 1023, 0, 255);
analogWrite(LEDpin, LEDbrightness);

delay(100);
}

 
 

Force Sensitive Resistor (FSR)

What is it?
“The FSR sensor detects physical pressure, squeezing and weight.”

How it works?
“The FSR is made of 2 layers separated by a spacer. The more one presses, the more of those Active Element dots touch the semiconductor and that makes the resistance go down.”

Specifications:

  • Size: 1/2" (12.5mm) diameter active area by 0.02" thick (Interlink does have some that are as large as 1.5"x1.5")

  • Price $7.00 from the Adafruit shop

  • Resistance range: Infinite/open circuit (no pressure), 100KΩ (light pressure) to 200Ω (max. pressure)

  • Force range: 0 to 20 lb. (0 to 100 Newtons) applied evenly over the 0.125 sq in surface area

  • Power supply: Any! Uses less than 1mA of current (depends on any pullup/down resistors used and supply voltage)

Source: 
https://learn.adafruit.com/force-sensitive-resistor-fsr/overview

Lab 4: Drawing & Animation 

To Do 

Use the P5 web editor to draw shapes and use variables to somehow animate them. This could be a portrait, a scene, an initial video game prototype, etc.

https://editor.p5js.org/dianaguerra14/full/ajwfZuGBK

function drawEye(x, y,eyeSize,pupilSize) {
//calculate the position of the pupil
var pupil = createVector(mouseX, mouseY);
pupil.sub(x,y);
pupil.limit((eyeSize -pupilSize) / 2);
pupil.add(x, y);

// Draw the eye and pupil
fill(135,206,250);
ellipse(x, y,eyeSize,eyeSize);
fill(173,255,47);
circle(400,200,125,50);
fill(0)
ellipse(pupil.x,pupil.y,pupilSize,pupilSize);
}

function setup() {
createCanvas(600,600);
strokeWeight(0);
}

function draw() {
background(240);
drawEye(200,200,125,50);// Left eye
drawEye(400,200,125,50);// Right eye

fill(255,192,203)
triangle(350, 320, 250, 320, 300, 370);
fill(255,192,203);
ellipse(300,450,130,80);
fill(240);
ellipse(300,430,130,80);

fill(0)
triangle(250, 100, 120, 120, 180, 20);
triangle(450, 100, 330, 100, 400, 20);
}

 
 

Lab 7: Motors

Make something move. Try to use an analog sensor.

Blog about your work. Include code, photo, video, and/or schematics as appropriate.

#include <Servo.h> // include the servo library
Servo servoMotor; // creates an instance of the servo object to control a servo
int servoPin = 7; // Control pin for servo motor

void setup() {
Serial.begin(9600); // initialize serial communications
servoMotor.attach(servoPin); // attaches the servo on pin 7 to the servo object
}

void loop()
{
int analogValue = analogRead(A0); // read the analog input
Serial.println(analogValue); // print it

// if your sensor's range is less than 0 to 1023, you'll need to
// modify the map() function to use the values you discovered:

int servoAngle = map(analogValue, 0, 1023, 0, 179);
// move the servo using the angle from the sensor:

servoMotor.write(servoAngle);
}

 
 

Lab 8: P5.js to Arduino

Arduino

int led = 11; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
// the setup routine runs once when you press reset:

void setup() {
// declare pin 5 to be an output:
pinMode(led, OUTPUT);
// initialize serial communications
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
if (Serial.available() > 0) { // if there's serial data available
int inByte = Serial.read(); // read it
// Serial.write(inByte); // send it back out as raw binary data
analogWrite(led, inByte); // use it to set the LED brightness
}
}

P5.js

let serial;
let latestData = "waiting for data"; // you'll use this to write incoming data to the canvas

function setup() {
createCanvas(windowWidth, windowHeight);
// Instantiate our SerialPort object
serial = new p5.SerialPort();
// Get a list the ports available
// You should have a callback defined to see the results
serial.list();

serial.open("/dev/tty.usbmodem142301");
// Here are the callbacks that you can register
// When we connect to the underlying server
serial.on('connected', serverConnected);
// When we get a list of serial ports that are available
serial.on('list', gotList);

// OR
//serial.onList(gotList);
// When we some data from the serial port
serial.on('data', gotData);
// OR
//serial.onData(gotData);
// When or if we get an error
serial.on('error', gotError);
// OR
//serial.onError(gotError);
// When our serial port is opened and ready for read/write
serial.on('open', gotOpen);
// OR
//serial.onOpen(gotOpen);
serial.on('close', gotClose);
}

function serverConnected() {
print("Connected to Server");
}

function gotList(thelist) {
print("List of Serial Ports:");
// theList is an array of their names
for (let i = 0; i < thelist.length; i++) {
// Display in the console
print(i + " " + thelist[i]);
}
}

// Connected to our serial device
function gotOpen() {
print("Serial Port is Open");
}

function gotClose(){
print("Serial Port is Closed");
latestData = "Serial Port is Closed";
}
function gotError(theerror) {
print(theerror);
}

// There is data available to work with from the serial port
function gotData() {
let currentString = serial.readLine();
latestData = currentString.split(","); // split where there's a comma
if (!currentString) return; // if the string is empty, do no more
print(latestData); // print the string
}

// We got raw from the serial port
function gotRawData(thedata) {
print("gotRawData" + thedata);
}

function draw() {
//parseInt turns the String data from the arduino
//into an integer we can use for math
let r = map(int(latestData[0]),0,600,0,255);
let b = map(int(latestData[1]),0,1023,0,255);

background(r,0,b);
fill(255);
text(latestData, 10, 10);
}

 
 

Final Project Proposal

For my final project, I intend to build an interactive piece that will use MTA data to affect sound. This piece will be built as a collaboration with another artist, who already started working on its first component. The first part of the project will be built using Python and will gather data from the MTA on train circulation. Depending on the location of the L train (in transit/in the station), the sound volume will change. The second component of the project will be sound that follows a narration in Spanish. This sound will be accompanied by a 3D animation built on P5.js and (ideally) will include text due to the need of subtitles in English.

The project is inspired by the film “News From Home”, directed by Belgian/American filmmaker Chantal Akerman and released in 1977. In this film, Akerman shows the New York City landscape of the 70’s while reading letters from her family back in Belgium. A particular characteristic of the film is the fact that Akerman’s voice is, sometimes, covered by the noise of the city.