Category Archives: Week 16

Final Project

Concept:

This was a game I designed for the final project of Parsons MFADT Physical Computing class. The goal of this game is to control and mix R/G/B color values to match the background color within 10 seconds each level. I used three photoresistors connected to arduino uno to sense the color value controlled by 1 to 3 players, and use openframeworks to build the user interface of this game.

DSC01912DSC01928 DSC01922 DSC01927 _DSC2363 _DSC2370

Code:

Continue reading Final Project

Final Project: Uglydoll Maker

Using a controller with 3 potentiometers – one to select the color, tab, and attribute – make your very own Uglydoll! This project was made using Arduino and Processing.

fbguj

controller

// Jessy Jo Gomez
// uglydoll maker (final)

float currentTab = 1;
float currentBox = 0;
float currentColor = 0;
float bodyType = 0;
float eyesType = 0;
float noseType = 2;
float mouthType = 0;

int bodyX = 1;
int bodyY = 1;
int eyesX = 1;
int eyesY = 1;
int noseX = 1;
int noseY = 1;
int mouthX = 1;
int mouthY = 1;

int selectColor = 0;
int selectTab = 0;
int selectAttribute = 0;

PImage template;
PImage tabBody;
PImage tabEyes;
PImage tabNose;
PImage tabMouth;
PImage currentBody;
PImage currentEyes;
PImage currentNose;
PImage currentMouth;

// TODO 1: copy these (3 lines):
import processing.serial.*;
Serial port; // The serial port object
boolean sending = false;

void setup() {

// TODO 2: copy these (2 lines):
// Using the first available port (might be different on your computer)
port = new Serial(this, Serial.list()[0], 9600);

size (550, 400);

template = loadImage(“template.png”);
currentBody = loadImage(“spacer.gif”);
currentEyes = loadImage(“spacer.gif”);
currentNose = loadImage(“spacer.gif”);
currentMouth = loadImage(“spacer.gif”);
tabBody = loadImage(“tabBody.png”);
tabEyes = loadImage(“tabEyes.png”);
tabNose = loadImage(“tabNose.png”);
tabMouth = loadImage(“tabMouth.png”);
}

void draw() {

image(template, 0, 0);
image(currentBody, bodyX, bodyY);
image(currentEyes, eyesX, eyesY);
image(currentNose, noseX, noseY);
image(currentMouth, mouthX, mouthY);

// tab positions

if ( selectTab > 0 && selectTab < 63 ) {
currentTab = 1;
}
if ( selectTab > 63 && selectTab < 126 ) {
currentTab = 2;
}
if ( selectTab > 126 && selectTab < 189 ) {
currentTab = 3;
}
if ( selectTab > 189 && selectTab < 255 ) {
currentTab = 4;
}

// color positions

if ( selectColor > 0 && selectColor < 31 ) {
currentColor = 0;
}
if ( selectColor > 31 && selectColor < 62 ) {
currentColor = 1;
}
if ( selectColor > 62 && selectColor < 93 ) {
currentColor = 2;
}
if ( selectColor > 93 && selectColor < 124 ) {
currentColor = 3;
}
if ( selectColor > 124 && selectColor < 155 ) {
currentColor = 4;
}
if ( selectColor > 155 && selectColor < 186 ) {
currentColor = 5;
}
if ( selectColor > 186 && selectColor < 217 ) {
currentColor = 6;
}
if ( selectColor > 217 && selectColor < 255 ) {
currentColor = 7;
}

// body tab

if ( currentTab == 1 ) {
image(tabBody, 288, -1);
if ( selectAttribute > 0 && selectAttribute < 42 ) {
currentBody = loadImage(“baboGrey.png”);
bodyType = 1;
bodyX = 205;
bodyY = 213;
}
if ( selectAttribute > 42 && selectAttribute < 84 ) {
currentBody = loadImage(“plunkoGrey.png”);
bodyType = 2;
bodyX = 206;
bodyY = 174;
}
if ( selectAttribute > 84 && selectAttribute < 126 ) {
currentBody = loadImage(“icebatGrey.png”);
bodyType = 3;
bodyX = 182;
bodyY = 189;
}
if ( selectAttribute > 126 && selectAttribute < 168 ) {
currentBody = loadImage(“uglywormGrey.png”);
bodyType = 4;
bodyX = 208;
bodyY = 218;
}
if ( selectAttribute > 168 && selectAttribute < 210 ) {
currentBody = loadImage(“wedgeheadGrey.png”);
bodyType = 5;
bodyX = 218;
bodyY = 218;
}
if ( selectAttribute > 210 && selectAttribute < 255 ) {
currentBody = loadImage(“feebeeGrey.png”);
bodyType = 6;
bodyX = 214;
bodyY = 186;
}
}

// babo’s colors

if ( bodyType == 1 ) {
if ( currentColor == 0 ) {
currentBody = loadImage(“baboGrey.png”);
}
if ( currentColor == 1 ) {
currentBody = loadImage(“baboRed.png”);
}
if ( currentColor == 2 ) {
currentBody = loadImage(“baboOrange.png”);
}
if ( currentColor == 3 ) {
currentBody = loadImage(“baboYellow.png”);
}
if ( currentColor == 4 ) {
currentBody = loadImage(“baboGreen.png”);
}
if ( currentColor == 5 ) {
currentBody = loadImage(“baboBlue.png”);
}
if ( currentColor == 6 ) {
currentBody = loadImage(“baboPurple.png”);
}
if ( currentColor == 7 ) {
currentBody = loadImage(“baboBlack.png”);
}
}

// plunko’s colors

if ( bodyType == 2 ) {
if ( currentColor == 0 ) {
currentBody = loadImage(“plunkoGrey.png”);
}
if ( currentColor == 1 ) {
currentBody = loadImage(“plunkoRed.png”);
}
if ( currentColor == 2 ) {
currentBody = loadImage(“plunkoOrange.png”);
}
if ( currentColor == 3 ) {
currentBody = loadImage(“plunkoYellow.png”);
}
if ( currentColor == 4 ) {
currentBody = loadImage(“plunkoGreen.png”);
}
if ( currentColor == 5 ) {
currentBody = loadImage(“plunkoBlue.png”);
}
if ( currentColor == 6 ) {
currentBody = loadImage(“plunkoPurple.png”);
}
if ( currentColor == 7 ) {
currentBody = loadImage(“plunkoBlack.png”);
}
}

// icebat’s colors

if ( bodyType == 3 ) {
if ( currentColor == 0 ) {
currentBody = loadImage(“icebatGrey.png”);
}
if ( currentColor == 1 ) {
currentBody = loadImage(“icebatRed.png”);
}
if ( currentColor == 2 ) {
currentBody = loadImage(“icebatOrange.png”);
}
if ( currentColor == 3 ) {
currentBody = loadImage(“icebatYellow.png”);
}
if ( currentColor == 4 ) {
currentBody = loadImage(“icebatGreen.png”);
}
if ( currentColor == 5 ) {
currentBody = loadImage(“icebatBlue.png”);
}
if ( currentColor == 6 ) {
currentBody = loadImage(“icebatPurple.png”);
}
if ( currentColor == 7 ) {
currentBody = loadImage(“icebatBlack.png”);
}
}

// uglyworm’s colors

if ( bodyType == 4 ) {
if ( currentColor == 0 ) {
currentBody = loadImage(“uglywormGrey.png”);
}
if ( currentColor == 1 ) {
currentBody = loadImage(“uglywormRed.png”);
}
if ( currentColor == 2 ) {
currentBody = loadImage(“uglywormOrange.png”);
}
if ( currentColor == 3 ) {
currentBody = loadImage(“uglywormYellow.png”);
}
if ( currentColor == 4 ) {
currentBody = loadImage(“uglywormGreen.png”);
}
if ( currentColor == 5 ) {
currentBody = loadImage(“uglywormBlue.png”);
}
if ( currentColor == 6 ) {
currentBody = loadImage(“uglywormPurple.png”);
}
if ( currentColor == 7 ) {
currentBody = loadImage(“uglywormBlack.png”);
}
}

// wedgehead’s colors

if ( bodyType == 5 ) {
if ( currentColor == 0 ) {
currentBody = loadImage(“wedgeheadGrey.png”);
}
if ( currentColor == 1 ) {
currentBody = loadImage(“wedgeheadRed.png”);
}
if ( currentColor == 2 ) {
currentBody = loadImage(“wedgeheadOrange.png”);
}
if ( currentColor == 3 ) {
currentBody = loadImage(“wedgeheadYellow.png”);
}
if ( currentColor == 4 ) {
currentBody = loadImage(“wedgeheadGreen.png”);
}
if ( currentColor == 5 ) {
currentBody = loadImage(“wedgeheadBlue.png”);
}
if ( currentColor == 6 ) {
currentBody = loadImage(“wedgeheadPurple.png”);
}
if ( currentColor == 7 ) {
currentBody = loadImage(“wedgeheadBlack.png”);
}
}

// feebee’s colors

if ( bodyType == 6 ) {
if ( currentColor == 0 ) {
currentBody = loadImage(“feebeeGrey.png”);
}
if ( currentColor == 1 ) {
currentBody = loadImage(“feebeeRed.png”);
}
if ( currentColor == 2 ) {
currentBody = loadImage(“feebeeOrange.png”);
}
if ( currentColor == 3 ) {
currentBody = loadImage(“feebeeYellow.png”);
}
if ( currentColor == 4 ) {
currentBody = loadImage(“feebeeGreen.png”);
}
if ( currentColor == 5 ) {
currentBody = loadImage(“feebeeBlue.png”);
}
if ( currentColor == 6 ) {
currentBody = loadImage(“feebeePurple.png”);
}
if ( currentColor == 7 ) {
currentBody = loadImage(“feebeeBlack.png”);
}
}

// eyes tab

if ( currentTab == 2 ) {
image(tabEyes, 288, -1);
if ( selectAttribute > 0 && selectAttribute < 42 ) {
currentEyes = loadImage(“eyes1.png”);
eyesType = 1;
}
if ( selectAttribute > 42 && selectAttribute < 84 ) {
currentEyes = loadImage(“eyes2.png”);
eyesType = 2;
}
if ( selectAttribute > 84 && selectAttribute < 126 ) {
currentEyes = loadImage(“eyes3.png”);
eyesType = 3;
}
if ( selectAttribute > 126 && selectAttribute < 168 ) {
currentEyes = loadImage(“eyes4.png”);
eyesType = 4;
}
if ( selectAttribute > 168 && selectAttribute < 210 ) {
currentEyes = loadImage(“eyes5.png”);
eyesType = 5;
}
if ( selectAttribute > 210 && selectAttribute < 255 ) {
currentEyes = loadImage(“eyes6.png”);
eyesType = 6;
}
}

if ( bodyType == 0 ) {
currentEyes = loadImage(“spacer.gif”);
}

// babo’s eyes

if ( bodyType == 1 ) {
if ( eyesType == 1 || eyesType == 4 || eyesType == 6 ) {
eyesX = 243;
eyesY = 233;
}
if ( eyesType == 2 || eyesType == 5 ) {
eyesX = 263;
eyesY = 233;
}
if ( eyesType == 3 ) {
eyesX = 245;
eyesY = 226;
}
}

// plunko’s eyes

if ( bodyType == 2 ) {
if ( eyesType == 1 || eyesType == 4 || eyesType == 6 ) {
eyesX = 250;
eyesY = 227;
}
if ( eyesType == 2 || eyesType == 5 ) {
eyesX = 270;
eyesY = 227;
}
if ( eyesType == 3 ) {
eyesX = 252;
eyesY = 220;
}
}

// icebat’s eyes

if ( bodyType == 3 ) {
if ( eyesType == 1 || eyesType == 4 || eyesType == 6 ) {
eyesX = 243;
eyesY = 233;
}
if ( eyesType == 2 || eyesType == 5 ) {
eyesX = 263;
eyesY = 233;
}
if ( eyesType == 3 ) {
eyesX = 245;
eyesY = 226;
}
}

// uglyworm’s eyes

if ( bodyType == 4 ) {
if ( eyesType == 1 || eyesType == 4 || eyesType == 6 ) {
eyesX = 229;
eyesY = 233;
}
if ( eyesType == 2 || eyesType == 5 ) {
eyesX = 249;
eyesY = 233;
}
if ( eyesType == 3 ) {
eyesX = 231;
eyesY = 226;
}
}

// wedgehead’s eyes

if ( bodyType == 5 ) {
if ( eyesType == 1 || eyesType == 4 || eyesType == 6 ) {
eyesX = 243;
eyesY = 230;
}
if ( eyesType == 2 || eyesType == 5 ) {
eyesX = 263;
eyesY = 230;
}
if ( eyesType == 3 ) {
eyesX = 245;
eyesY = 223;
}
}

// feebee’s eyes

if ( bodyType == 6 ) {
if ( eyesType == 1 || eyesType == 4 || eyesType == 6 ) {
eyesX = 249;
eyesY = 200;
}
if ( eyesType == 2 || eyesType == 5 ) {
eyesX = 269;
eyesY = 200;
}
if ( eyesType == 3 ) {
eyesX = 251;
eyesY = 193;
}
}

// nose tab

if ( currentTab == 3 ) {
image(tabNose, 288, -1);
if ( selectAttribute > 0 && selectAttribute < 127 ) {
currentNose = loadImage(“nose1.png”);
noseType = 1;
}
if ( selectAttribute > 127 && selectAttribute < 255 ) {
currentNose = loadImage(“spacer.gif”);
noseType = 2;
}
}

if ( bodyType == 0 ) {
currentNose = loadImage(“spacer.gif”);
}

// nose positions

if ( bodyType == 1 && noseType == 1 || bodyType == 1 && noseType == 2 ) {
noseX = 258;
noseY = 251;
}
if ( bodyType == 2 && noseType == 1 || bodyType == 2 && noseType == 2 ) {
noseX = 265;
noseY = 245;
}
if ( bodyType == 3 && noseType == 1 || bodyType == 3 && noseType == 2 ) {
noseX = 258;
noseY = 251;
}
if ( bodyType == 4 && noseType == 1 || bodyType == 4 && noseType == 2 ) {
noseX = 244;
noseY = 251;
}
if ( bodyType == 5 && noseType == 1 || bodyType == 5 && noseType == 2 ) {
noseX = 258;
noseY = 248;
}
if ( bodyType == 6 && noseType == 1 || bodyType == 6 && noseType == 2 ) {
noseX = 264;
noseY = 218;
}

// mouth tab

if ( currentTab == 4 ) {
image(tabMouth, 288, -1);
if ( selectAttribute > 0 && selectAttribute < 42 ) {
currentMouth = loadImage(“mouth1.png”);
mouthType = 1;
}
if ( selectAttribute > 42 && selectAttribute < 84 ) {
currentMouth = loadImage(“mouth2.png”);
mouthType = 2;
}
if ( selectAttribute > 84 && selectAttribute < 126 ) {
currentMouth = loadImage(“mouth3.png”);
mouthType = 3;
}
if ( selectAttribute > 126 && selectAttribute < 168 ) {
currentMouth = loadImage(“mouth4.png”);
mouthType = 4;
}
if ( selectAttribute > 168 && selectAttribute < 210 ) {
currentMouth = loadImage(“mouth5.png”);
mouthType = 5;
}
if ( selectAttribute > 210 && selectAttribute < 255 ) {
currentMouth = loadImage(“mouth6.png”);
mouthType = 6;
}
}

if ( bodyType == 0 ) {
currentMouth = loadImage(“spacer.gif”);
}

// babo’s mouth

if ( bodyType == 1 && noseType == 2 && mouthType == 1 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 1 && noseType == 1 && mouthType == 1 ) {
mouthX = 240;
mouthY = 265;
}
if ( bodyType == 1 && noseType == 2 && mouthType == 2 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 1 && noseType == 1 && mouthType == 2 ) {
mouthX = 240;
mouthY = 265;
}
if ( bodyType == 1 && noseType == 2 && mouthType == 3 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 1 && noseType == 1 && mouthType == 3 ) {
mouthX = 240;
mouthY = 265;
}
if ( bodyType == 1 && noseType == 2 && mouthType == 4 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 1 && noseType == 1 && mouthType == 4 ) {
mouthX = 240;
mouthY = 265;
}
if ( bodyType == 1 && noseType == 2 && mouthType == 5 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 1 && noseType == 1 && mouthType == 5 ) {
mouthX = 240;
mouthY = 265;
}
if ( bodyType == 1 && noseType == 2 && mouthType == 6 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 1 && noseType == 1 && mouthType == 6 ) {
mouthX = 240;
mouthY = 265;
}

// plunko’s mouth

if ( bodyType == 2 && noseType == 2 && mouthType == 1 ) {
mouthX = 247;
mouthY = 250;
}
if ( bodyType == 2 && noseType == 1 && mouthType == 1 ) {
mouthX = 247;
mouthY = 259;
}
if ( bodyType == 2 && noseType == 2 && mouthType == 2 ) {
mouthX = 247;
mouthY = 250;
}
if ( bodyType == 2 && noseType == 1 && mouthType == 2 ) {
mouthX = 247;
mouthY = 259;
}
if ( bodyType == 2 && noseType == 2 && mouthType == 3 ) {
mouthX = 247;
mouthY = 250;
}
if ( bodyType == 2 && noseType == 1 && mouthType == 3 ) {
mouthX = 247;
mouthY = 259;
}
if ( bodyType == 2 && noseType == 2 && mouthType == 4 ) {
mouthX = 247;
mouthY = 250;
}
if ( bodyType == 2 && noseType == 1 && mouthType == 4 ) {
mouthX = 247;
mouthY = 259;
}
if ( bodyType == 2 && noseType == 2 && mouthType == 5 ) {
mouthX = 247;
mouthY = 250;
}
if ( bodyType == 2 && noseType == 1 && mouthType == 5 ) {
mouthX = 247;
mouthY = 259;
}
if ( bodyType == 2 && noseType == 2 && mouthType == 6 ) {
mouthX = 247;
mouthY = 250;
}
if ( bodyType == 2 && noseType == 1 && mouthType == 6 ) {
mouthX = 247;
mouthY = 259;
}

// icebat’s mouth

if ( bodyType == 3 && noseType == 2 && mouthType == 1 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 3 && noseType == 1 && mouthType == 1 ) {
mouthX = 240;
mouthY = 265;
}
if ( bodyType == 3 && noseType == 2 && mouthType == 2 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 3 && noseType == 1 && mouthType == 2 ) {
mouthX = 240;
mouthY = 265;
}
if ( bodyType == 3 && noseType == 2 && mouthType == 3 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 3 && noseType == 1 && mouthType == 3 ) {
mouthX = 240;
mouthY = 265;
}
if ( bodyType == 3 && noseType == 2 && mouthType == 4 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 3 && noseType == 1 && mouthType == 4 ) {
mouthX = 240;
mouthY = 265;
}
if ( bodyType == 3 && noseType == 2 && mouthType == 5 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 3 && noseType == 1 && mouthType == 5 ) {
mouthX = 240;
mouthY = 265;
}
if ( bodyType == 3 && noseType == 2 && mouthType == 6 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 3 && noseType == 1 && mouthType == 6 ) {
mouthX = 240;
mouthY = 265;
}

// uglyworm’s mouth

if ( bodyType == 4 && noseType == 2 && mouthType == 1 ) {
mouthX = 226;
mouthY = 256;
}
if ( bodyType == 4 && noseType == 1 && mouthType == 1 ) {
mouthX = 226;
mouthY = 265;
}
if ( bodyType == 4 && noseType == 2 && mouthType == 2 ) {
mouthX = 226;
mouthY = 256;
}
if ( bodyType == 4 && noseType == 1 && mouthType == 2 ) {
mouthX = 226;
mouthY = 265;
}
if ( bodyType == 4 && noseType == 2 && mouthType == 3 ) {
mouthX = 226;
mouthY = 256;
}
if ( bodyType == 4 && noseType == 1 && mouthType == 3 ) {
mouthX = 226;
mouthY = 265;
}
if ( bodyType == 4 && noseType == 2 && mouthType == 4 ) {
mouthX = 226;
mouthY = 256;
}
if ( bodyType == 4 && noseType == 1 && mouthType == 4 ) {
mouthX = 226;
mouthY = 265;
}
if ( bodyType == 4 && noseType == 2 && mouthType == 5 ) {
mouthX = 226;
mouthY = 256;
}
if ( bodyType == 4 && noseType == 1 && mouthType == 5 ) {
mouthX = 226;
mouthY = 265;
}
if ( bodyType == 4 && noseType == 2 && mouthType == 6 ) {
mouthX = 226;
mouthY = 256;
}
if ( bodyType == 4 && noseType == 1 && mouthType == 6 ) {
mouthX = 226;
mouthY = 265;
}

// wedgehead’s mouth

if ( bodyType == 5 && noseType == 2 && mouthType == 1 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 5 && noseType == 1 && mouthType == 1 ) {
mouthX = 240;
mouthY = 262;
}
if ( bodyType == 5 && noseType == 2 && mouthType == 2 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 5 && noseType == 1 && mouthType == 2 ) {
mouthX = 240;
mouthY = 262;
}
if ( bodyType == 5 && noseType == 2 && mouthType == 3 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 5 && noseType == 1 && mouthType == 3 ) {
mouthX = 240;
mouthY = 262;
}
if ( bodyType == 5 && noseType == 2 && mouthType == 4 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 5 && noseType == 1 && mouthType == 4 ) {
mouthX = 240;
mouthY = 262;
}
if ( bodyType == 5 && noseType == 2 && mouthType == 5 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 5 && noseType == 1 && mouthType == 5 ) {
mouthX = 240;
mouthY = 262;
}
if ( bodyType == 5 && noseType == 2 && mouthType == 6 ) {
mouthX = 240;
mouthY = 256;
}
if ( bodyType == 5 && noseType == 1 && mouthType == 6 ) {
mouthX = 240;
mouthY = 262;
}

// feebee’s mouth

if ( bodyType == 6 && noseType == 2 && mouthType == 1 ) {
mouthX = 243;
mouthY = 223;
}
if ( bodyType == 6 && noseType == 1 && mouthType == 1 ) {
mouthX = 243;
mouthY = 232;
}
if ( bodyType == 6 && noseType == 2 && mouthType == 2 ) {
mouthX = 243;
mouthY = 223;
}
if ( bodyType == 6 && noseType == 1 && mouthType == 2 ) {
mouthX = 243;
mouthY = 232;
}
if ( bodyType == 6 && noseType == 2 && mouthType == 3 ) {
mouthX = 243;
mouthY = 223;
}
if ( bodyType == 6 && noseType == 1 && mouthType == 3 ) {
mouthX = 243;
mouthY = 232;
}
if ( bodyType == 6 && noseType == 2 && mouthType == 4 ) {
mouthX = 243;
mouthY = 223;
}
if ( bodyType == 6 && noseType == 1 && mouthType == 4 ) {
mouthX = 243;
mouthY = 232;
}
if ( bodyType == 6 && noseType == 2 && mouthType == 5 ) {
mouthX = 243;
mouthY = 223;
}
if ( bodyType == 6 && noseType == 1 && mouthType == 5 ) {
mouthX = 243;
mouthY = 232;
}
if ( bodyType == 6 && noseType == 2 && mouthType == 6 ) {
mouthX = 243;
mouthY = 223;
}
if ( bodyType == 6 && noseType == 1 && mouthType == 6 ) {
mouthX = 243;
mouthY = 232;
}

// TODO 3: add this if statement (4 lines) to the end of your draw() function
// until we start sending, ask for values
if ( !sending ) {
port.write(65); // arbitrary character (the letter A)
}
}

// TODO 4: copy this whole function into your code (at the end)
// Called whenever there is something available to read
void serialEvent(Serial port) {

sending = true;

// Data from the Serial port is read in serialEvent() using the readStringUntil()
// function with * as the end character.
String input = port.readStringUntil(‘*’);

if (input != null) {
// Print message received
println( “Receiving:” + input);

// The data is split into an array of Strings with a comma or
// asterisk as a delimiter and converted into an array of integers.
int[] vals = int(splitTokens(input, “,*”));

// the num variable will hold the value we’ve read from the serial connection
selectColor = vals[0];

// TODO 5: If you are using more than one sensor, set the other values here. For example:
selectTab = vals[1];
selectAttribute = vals[2];
// etc.
// And just make sure these variables are declared up top (eg, “int otherNum;”)
}

// When finished ask for values again
port.write(65);
}

//Jessy Jo Gomez
//”communication”

int firstSensor = 0; // first analog sensor
int secondSensor = 0; // second analog sensor
int thirdSensor = 0; // third analog sensor
int inByte = 0; // incoming serial byte

void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);
}

void loop()
{
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
// read first analog input, divide by 4 to make the range 0-255:
firstSensor = analogRead(3)/4;
// read second analog input, divide by 4 to make the range 0-255:
secondSensor = analogRead(4)/4;
// read third analog input, divide by 4 to make the range 0-255:
thirdSensor = analogRead(5)/4;

// delay 10ms to let the ADC recover:
delay(10);

// send sensor values:
// print each sensor value, then print a comma
Serial.print(firstSensor, DEC);
Serial.print(‘,’);
Serial.print(secondSensor, DEC);
Serial.print(‘,’);
Serial.print(thirdSensor, DEC);

// at the end, send a ‘*’ to end the message:
Serial.print(‘*’);

}
}

FINAL PROJECT

  • Concept

The topic of my project is “TALK TO ME”.

Contemporary, new kinds of technologies are changing people’s lives constantly. Sometimes we even can’t notice these changes are happening to us. However, technologies can’t really understand people’s emotion need. For instance, the mobile phones and the Internet make distance nothing but can’t make you feel really close to each other.

In this project, I design a sound piece to solve one emotional problem for roommates when they are dissatisfied with each other. You can also use this to give yourself some surprise.

It usually happens in my country that roommates don’t want talk to each other after quarreling and no one want to talk first. It kind of means you surrender if you talk first and really can make you lose face.  We are reactive culture type. We never confront, usually react to others’ actions and must not lose face. But we need to solve problem after quarreling and talk to each other is the only efficient method. How can we make people feel more comfortable to be the first one to talk?

Then I design a sound piece as a bridge to connect people together, initiate conversation. When you are dissatisfied with your roommate, you can use this sound piece to record message to him/her.

  • Function

IMG_3693

There are seven buttons on the wooden box. Because in China we always have six to seven roommates in dorm. Each roommate has one specific button for themselves. The big buttons and little stars combine together to make a letter “t”, which means “Talk to me”. The shape of the box is just like a tree truck and the shape of the edge is just like growth ring, which represents time.

Self-record mode: If you want to leave some message to yourself, you can just click on your button to record messages, then click on your button to save message. The machine can choose a random day from three days to one month. On that day, all the lights will be on and you click on your button to hear the one message from your self, just like a time capsule.

Contact mode: If you want to say something to your roommates but don’t want to knock on their doors or say something face by face, you can click on your button to record message, then click on your roommate’s button to save the message on his/her spot. All the lights will be on immediately to remind your roommates to listen to the message. Only the roommate who you leave message to can hear the message from you. Other roommates can only hear the message from themselves. Through this method, we can avoid the awkward of talking some dissatisfied things face by face and avoid the unpleasant feeling of talking first.

  • Structures and Pieces

I use 7 LED buttons, one NEO pixel ring, one microphone, one speaker with amplifier and one sound chip. It takes me a lot of time to put all these stuff into the wooden box.

IMG_3624 IMG_3626 IMG_3690 IMG_3689 IMG_3688IMG_3628 IMG_3691

  • Code

// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
#include <Adafruit_NeoPixel.h>

// define the pins used
#define RESET 9 // VS1053 reset pin (output)
#define CS 10 // VS1053 chip select pin (output)
#define DCS 8 // VS1053 Data/command select pin (output)
#define CARDCS A0 // Card chip select pin
#define DREQ A1 // VS1053 Data request, ideally an Interrupt pin

#define REC_BUTTON 7
#define PLAY_BUTTON 5

#define PIN 3

Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(RESET, CS, DCS, DREQ, CARDCS);

Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

File recording; // the file we will save our recording to
#define RECBUFFSIZE 128 // 64 or 128 bytes.
uint8_t recording_buffer[RECBUFFSIZE];

int led=2;
void setup() {
Serial.begin(9600);
Serial.println(“Record_Play”);

strip.begin();
strip.show();

rainbow(20);

pinMode(led, OUTPUT);

// initialise the music player
if (!musicPlayer.begin()) {
Serial.println(“VS1053 not found”);
while (1); // don’t do anything more
}

musicPlayer.sineTest(0x44, 500); // Make a tone to indicate VS1053 is working

if (!SD.begin(CARDCS)) {
Serial.println(“SD failed, or not present”);
while (1); // don’t do anything more
}
Serial.println(“SD OK!”);

// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(40,40);

// when the button is pressed, record!
pinMode(REC_BUTTON, INPUT);
digitalWrite(REC_BUTTON, HIGH);
pinMode(PLAY_BUTTON, INPUT);
digitalWrite(PLAY_BUTTON, HIGH);

// load plugin from SD card! We’ll use mono 44.1KHz, high quality
if (! musicPlayer.prepareRecordOgg(“v44k1q05.img”)) {
Serial.println(“Couldn’t load plugin!”);
while (1);
}
}

uint8_t isRecording = false;

int num;

void loop() {
if (!isRecording && !digitalRead(REC_BUTTON)) {
Serial.println(“Begin recording”);
isRecording = true;

digitalWrite(led, HIGH);

// Check if the file exists already
char filename[15];
strcpy(filename, “RECORD00.OGG”);
for (uint8_t i = 0; i < 100; i++) {
filename[6] = ‘0’ + i/10;
filename[7] = ‘0’ + i%10;

num=i;
// create if does not exist, do not open existing, write, sync after write
if (! SD.exists(filename)) {
break;
}
}
Serial.print(“Recording to “); Serial.println(filename);
recording = SD.open(filename, FILE_WRITE);
if (! recording) {
Serial.println(“Couldn’t open file to record!”);
while (1);
}
musicPlayer.startRecordOgg(true); // use microphone (for linein, pass in ‘false’)
}
if (isRecording)
saveRecordedData(isRecording);
if (isRecording && !digitalRead(REC_BUTTON)) {
Serial.println(“End recording”);

digitalWrite(led, LOW);

musicPlayer.stopRecordOgg();
isRecording = false;
// flush all the data!
saveRecordedData(isRecording);
// close it up
recording.close();
delay(100);
}

if(!isRecording && !digitalRead(PLAY_BUTTON)){
if (! musicPlayer.begin()) { // initialise the music player
Serial.println(F(“Couldn’t find VS1053, do you have the right pins defined?”));
while (1);
}
Serial.println(F(“VS1053 found”));

SD.begin(CARDCS); // initialise the SD card

// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(40,40);

// Timer interrupts are not suggested, better to use DREQ interrupt!
//musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

// If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
// audio playing
musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); // DREQ int

char filename[15];
strcpy(filename, “RECORD00.OGG”);
filename[6] = ‘0’ + num/10;
filename[7] = ‘0’ + num%10;
// Play one file, don’t return until complete

musicPlayer.playFullFile(filename);

// File is playing in the background
if (musicPlayer.stopped()) {
Serial.println(“Done playing music”);
}

delay(100);
}
}

uint16_t saveRecordedData(boolean isrecord) {
uint16_t written = 0;

// read how many words are waiting for us
uint16_t wordswaiting = musicPlayer.recordedWordsWaiting();

// try to process 256 words (512 bytes) at a time, for best speed
while (wordswaiting > 256) {
//Serial.print(“Waiting: “); Serial.println(wordswaiting);
// for example 128 bytes x 4 loops = 512 bytes
for (int x=0; x < 512/RECBUFFSIZE; x++) {
// fill the buffer!
for (uint16_t addr=0; addr < RECBUFFSIZE; addr+=2) {
uint16_t t = musicPlayer.recordedReadWord();
//Serial.println(t, HEX);
recording_buffer[addr] = t >> 8;
recording_buffer[addr+1] = t;
}
if (! recording.write(recording_buffer, RECBUFFSIZE)) {
Serial.print(“Couldn’t write “); Serial.println(RECBUFFSIZE);
while (1);
}
}
// flush 512 bytes at a time
recording.flush();
written += 256;
wordswaiting -= 256;
}

wordswaiting = musicPlayer.recordedWordsWaiting();
if (!isrecord) {
Serial.print(wordswaiting); Serial.println(” remaining”);
// wrapping up the recording!
uint16_t addr = 0;
for (int x=0; x < wordswaiting-1; x++) {
// fill the buffer!
uint16_t t = musicPlayer.recordedReadWord();
recording_buffer[addr] = t >> 8;
recording_buffer[addr+1] = t;
if (addr > RECBUFFSIZE) {
if (! recording.write(recording_buffer, RECBUFFSIZE)) {
Serial.println(“Couldn’t write!”);
while (1);
}
recording.flush();
addr = 0;
}
}
if (addr != 0) {
if (!recording.write(recording_buffer, addr)) {
Serial.println(“Couldn’t write!”); while (1);
}
written += addr;
}
musicPlayer.sciRead(VS1053_SCI_AICTRL3);
if (! (musicPlayer.sciRead(VS1053_SCI_AICTRL3) & _BV(2))) {
recording.write(musicPlayer.recordedReadWord() & 0xFF);
written++;
}
recording.flush();
}

return written;
}
//RING
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}

void rainbow(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, c); //turn every third pixel on
}
strip.show();

delay(wait);

for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
strip.show();

delay(wait);

for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r – g – b – back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 – WheelPos;
if(WheelPos < 85) {
return strip.Color(255 – WheelPos * 3, 0, WheelPos * 3);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 – WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 – WheelPos * 3, 0);
}
}

 

Final Project _ Qianjing Liu

2O8A09412O8A09412O8A0941

My new concept is making a device to express how noise affect our inner world.  The container is divided into two parts. One stand for our inner wold while the other one means the outside world. Since people can hardly concentrate on both the inner world and the outside world,  they have to struggle for more space.  Once the outside part got more room, it means the inner part has lost some.

When people stay in a noisy environment, they can hardly focus on their thought. Instead of thinking in their mind, they will pay more attention what is happening around. So I try to make the two parts of room available, and could change with the volume of sound.

To get the volume I used a sound sensor. And I used two servos to get a border, which divided the container into two parts,  moving with the change of environment. To make the loudness of  sound more visible, I use two fans, which could also map their speed with noisy environment. There are small feathers inside the container, so that they will fly in the container while it is noisy outside.

 

#include <Servo.h>
int sensor1=11;
int sensor2 =10;
int sensor3 =12;
int pos1=0;
int pos2;
int sensor = A5;
int loudness;

Servo myservo1;
Servo myservo2;

void setup(){
pinMode(sensor1,OUTPUT);
pinMode(sensor2,OUTPUT);
pinMode(sensor3,OUTPUT);
Serial.begin(9600);
pinMode(sensor,INPUT);
myservo1.attach(6);
myservo2.attach(9);
}

void loop(){
loudness = analogRead(sensor);
loudness = loudness -500;
if(loudness < 0){
loudness = 0-loudness;
}
if (loudness >=430){
analogWrite(sensor1,255);
analogWrite(sensor2,255);
digitalWrite(sensor3,HIGH);
if(pos1 < 75){
pos1++;
delay(15);
}
}
if (loudness <430){
analogWrite(sensor1,0);
analogWrite(sensor2,0);
digitalWrite(sensor3,LOW);
if(pos1 > 0){
pos1–;
delay(15);
}
}

pos2=180-pos1;
myservo1.write(pos1); // tell servo to go to position in variable ‘pos’
myservo2.write(pos2);
Serial.println(loudness);
}