All posts by shihwenchen

pcomp

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 Proposal

This is a game project using arduino and openFramwork.

Each player has a hand-held gadget with an arduino sensor and an LED light which can be pushed or squeezed to control the color composition on the screen. Players mix their own colors (R/G/B) to match the blended color with the border color shown on the screen — within a time limit. The more closely the colors match, the higher the score will be. The LED light of each player stands for the color he/she owns in a single stage. Colors will be rearranged in every new stage. For 4 players we even have a CMYK mode!

Input: Arduino sensor
Output: LED light, openFramwork animation on screen

螢幕快照 2014-11-21 上午6.26.44

螢幕快照 2014-11-21 上午6.26.58

Midterm: Little Bird Pet

The little bird jumps all the time. If you feed her by clicking the colorful ball, she will sing happily. But if you get closer, she will jump crazily and scream.

There’s a photoresistor, a flex sensor and a servo inside.

Code:

#include <Servo.h>

Servo myservo1; //360
int val1 = 0;
int val2 = 0;
int t1 = 80;
int t2 = 120;

int pos = 0;
int pos_l = 20;
int dir = 1;

int toneSpeed = 1800;
int speakerPin = 7;
int freq = 2000;
int feed = 2200;

int lightPin = 0;
int flexPin = 1;
int flexVal = 0;

void setup() {
myservo1.attach(9);
Serial.begin(9600);
pinMode(speakerPin, OUTPUT);
}
void loop() {
val1 = analogRead(lightPin);
//Serial.println(val1);
val1 = map(val1, 300, 800, 0, 180);
// Serial.println(val1);

flexVal = analogRead(flexPin);
Serial.println(flexVal);

if(flexVal < 8) {
tone(speakerPin, feed+flexVal*5, 8);
delay(10);
tone(speakerPin, feed+flexVal*5-150, 16);
noTone(speakerPin);
}

if(val1 <= t1) {
pos += 2 * dir;
noTone(speakerPin);
if(pos < pos_l) {
pos = pos_l;
dir *= -1;
}
else if(pos > pos_l+60) {
pos = pos_l+60;
dir *= -1;
}
}
else if(val1 > t1 && val1 <= t2) {
pos += 4 * dir;
noTone(speakerPin);

if(pos < pos_l) {
pos = pos_l;
dir *= -1;
}
else if(pos > pos_l+60) {
pos = pos_l+60;
dir *= -1;
}
}
else if(val1 > t2) {
pos += 5 * dir;
tone(speakerPin, freq+val1*5);
if(pos < pos_l) {
pos = pos_l;
dir *= -1;
}
else if(pos > pos_l+30) {
pos = pos_l+30;
dir *= -1;
}
}
// Serial.println(pos);
myservo1.write(pos);
delay(10);
}

homework for week 5: Music Box

The two dancers dance elegantly with the music Canon, and the colorful light blinking inside the box as well.

Code:

/*
Canon for summer night (with LED) by aNdY 2013
*/

#include “pitches.h”
#include <Servo.h>

Servo myservo1; //180
Servo myservo2; //360
int value1 = 360;
int value2 = 0;

// notes in the melody:
int CanonTone[] = {
NOTE_E3, NOTE_G4, NOTE_C5, NOTE_E5, NOTE_B2, NOTE_G4, NOTE_B4, NOTE_D5,
NOTE_C3, NOTE_E4, NOTE_A4, NOTE_C5, NOTE_G2, NOTE_E4, NOTE_G4, NOTE_B4,
NOTE_A2, NOTE_C4, NOTE_F4, NOTE_A4, NOTE_E1, NOTE_C4, NOTE_E4, NOTE_G4,
NOTE_A2, NOTE_D4, NOTE_F4, NOTE_A4, NOTE_B2, NOTE_D4, NOTE_G4, NOTE_B4,
NOTE_E3, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_F5,
NOTE_E5, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_F4, NOTE_G4,
NOTE_F4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_D4, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4,
NOTE_F4, NOTE_A4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_F5, NOTE_G5,
NOTE_E5, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_D5, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_B4,
NOTE_C5, NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_E4, NOTE_D4, NOTE_E4, NOTE_C5, NOTE_B4, NOTE_C5,
NOTE_A4, NOTE_C5, NOTE_B4, NOTE_A4, NOTE_G4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5,
NOTE_A4, NOTE_C5, NOTE_B4, NOTE_C5, NOTE_B4, NOTE_A4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_C5, NOTE_A4, NOTE_B4,
NOTE_C5,0
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8,
8,16,16,8,16,16,16,16,16,16,16,16,16, 16,
8,16,16,8,16,16,16,16,16,16,16,16,16, 16,
8,16,16,8,16,16,16,16,16,16,16,16,16, 16,
8,16,16,8,16,16,16,16,16,16,16,16,16, 16,
8,16,16,8,16,16,16,16,16,16,16,16,16, 16,
8,16,16,8,16,16,16,16,16,16,16,16,16, 16,
8,16,16,8,16,16,16,16,16,16,16,16,16, 16,
8,16,16,8,16,16,16,16,16,16,16,16,16, 16,
1
};

int toneSpeed = 1800; // set music speed
int ledPin;
int speakerPin = A0;
int thisNote;

void setup() {
myservo1.attach(13);
myservo2.attach(0);

thisNote = 0;
for(int pin = 1; pin <= 12; pin++) {
pinMode(pin, OUTPUT);
}
}
void loop() {
while(CanonTone[thisNote] > 0) {
// int flag = 0;
// if (flag == 0) {
// value1 += 10;
// if (value1 == 180) {
// flag = 1;
// }
// }
// else if (flag == 1){
// value1 -= 10;
// if (value1 == 0) {
// flag = 0;
// }
// }
if(thisNote < 32)
value1 -= 45;
else
value1 -= 30;
value2 += 1;
if(value1 <= 0) {
value1 += 360;
}
if(value2 >= 360) {
value1 -= 360;
}
myservo1.write(value1);
myservo2.write(value2);

int toneLevel = CanonTone[thisNote]; // get tone pitch
switch(toneLevel) {
case 262: // if C4, pin = 1
ledPin = 1;
break;
case 294: // if D4, pin = 2
ledPin = 2;
break;
case 330: // if E4, pin = 3
ledPin = 3;
break;
case 349:
ledPin = 4;
break;
case 392:
ledPin = 5;
break;
case 440:
ledPin = 6;
break;
case 494:
ledPin = 7;
break;
case 523:
ledPin = 8;
break;
case 587:
ledPin = 9;
break;
case 659:
ledPin = 10;
break;
case 698:
ledPin = 11;
break;
case 784:
ledPin = 12;
break;
default:
ledPin = 1;
break;
}
digitalWrite(ledPin, HIGH);

int noteDuration = toneSpeed / noteDurations[thisNote];
tone(speakerPin, CanonTone[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note’s duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
digitalWrite(ledPin, LOW);
delay(2);
thisNote++;
if(thisNote >= 144)
thisNote -= 144;
}
// noTone(speakerPin); // turn speaker off
}

homework for week 4: Little Piano

This is a little piano with 3 keys — red stands for C, green stands for E, and blue stands for G. Control the knock strength to change the key.

2014-09-26 08.45.04-1 拷貝

 

HW2_piano_bb

int sensorPin = 0;
int ledPinC = 2;
int ledPinE = 3;
int ledPinG = 4;
int threshold = 100;
int keyboard;

int speaker = 12;
int sensorValue = 0;

void setup() {
Serial.begin(9600);
pinMode(ledPinC, OUTPUT);
pinMode(ledPinE, OUTPUT);
pinMode(ledPinG, OUTPUT);
pinMode(speaker, OUTPUT);
}

void loop() {
int val = analogRead(sensorPin);

if (val >= threshold) {
sensorValue = map(val, 180, 400, 100, 500);

if(sensorValue >= 100 && sensorValue < 200) {
keyboard = 131;
tone(speaker, keyboard);
digitalWrite(ledPinC, HIGH);
delay(100);
digitalWrite(ledPinC, LOW);
noTone(speaker);
}
else if(sensorValue >= 200 && sensorValue < 300) {
keyboard = 330;
tone(speaker, keyboard);
digitalWrite(ledPinE, HIGH);
delay(100);
digitalWrite(ledPinE, LOW);
noTone(speaker);
}
else if(sensorValue >= 300 && sensorValue < 400) {
keyboard = 784;
tone(speaker, keyboard);
digitalWrite(ledPinG, HIGH);
delay(100);
digitalWrite(ledPinG, LOW);
noTone(speaker);
}
Serial.println(keyboard);
}
}

homework for week 2: Blink and lighten

The blink frequency and brightness of LED can be both controlled at the same time by the knob.

IMG_9051_2

 

 

/*
LED -> GND, 9
KNOB -> (middle) ANALOG IN 0
-> (other) 5V, GND
*/

int buttonPin = 2;
int ledPin = 9;
int potpin = 0;
int val, f;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}

void loop() {
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 179);
f = (180 – val) * 2;

analogWrite(ledPin, val);
delay(f);
analogWrite(ledPin, val/3);
delay(f);
}

INTRODUCTION – Angela

10479668_10202448534240140_8262608215861270580_o

I am Shih-wen Chen from Taiwan, you can call me Angela. My background is computer science and I did some freelance jobs of graphic and web design. I had a job focus on Digital Humanity after college for two years.

I did a little physical computing using FPGA board for a class in college, but I’ve never touched Arduino. Most of the time I concentrated on software side. So I’d like to try and explore this area and make something fun!