Videos

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);
}
}

 

Midterm_Haotian Li

Drawing Robot

This robot can draw four different shapes according to the distance. The shapes are rectangle, trapezoid, transverse line and vertical line. It draws vertical lines when distance is between 27cm and 37 cm, transverse lines when distance is between 20cm and 27 cm, rectangle when distance is between 10 cm and 20 cm, trapezoid when distance is between 0 cm and 10 cm. The robot is sleeping when it lies down so it doesn’t work. It begins working when it stands up.

I use ultrasonic distance sensor to measure the distance and use three servos to control the arms and draw shapes. There is a triple-axis accelerometer inside to control it working or not.

I design the machinery structures and out looking of the robot in AI. Then use laser cutter to make all the components.

IMG_3281 IMG_3283 647C35D0-B629-42AA-BC74-290FD7DF29ED

Code_______________________

#define SERVOPINLIFT 2
#define SERVOPINLEFT 3
#define SERVOPINRIGHT 4

#define trigPin 9
#define echoPin 8

#include <Servo.h>

Servo servo1; //
Servo servo2; //
Servo servo3; //

//ADXL 335
const int xInput = A0;
const int yInput = A1;
const int zInput = A2;

int xRawMin = 512;
int xRawMax = 512;

int yRawMin = 512;
int yRawMax = 512;

int zRawMin = 512;
int zRawMax = 512;

const int sampleSize = 10;

int led1=13;
int led2=12;

void setup()
{
analogReference(EXTERNAL);
Serial.begin(9600);
servo1.attach(SERVOPINLIFT); // lifting servo
servo2.attach(SERVOPINLEFT); // left servo
servo3.attach(SERVOPINRIGHT); // right servo
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);

servo1.write(25);
servo2.write(30);
servo3.write(150);

}

void loop()
{

int xRaw = ReadAxis(xInput);
int yRaw = ReadAxis(yInput);
int zRaw = ReadAxis(zInput);

int duration,distance;
digitalWrite(trigPin,HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin,LOW);
duration=pulseIn(echoPin,HIGH);
distance=(duration/2)/29.1;
Serial.println(distance);
delay(100);

if(zRaw>470){
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);

//up down
if(distance>37){
servo2.write(30);
servo3.write(150);
delay(15);
}

if(distance>27 && distance<=37){
for(int i=20; i<50; i+=1)
{
servo2.write(i);
servo3.write(180-i);
delay(15);
}

for(int i=50; i>20; i-=1)
{
servo2.write(i);
servo3.write(180-i);
delay(15);
}
}

//left right
if(distance>20 && distance<=27){
for(int i=85; i>20; i-=1)
{
servo2.write(i);
servo3.write(180+i-85);
delay(15);
}
for(int i=20; i<85; i+=1)
{
servo2.write(i);
servo3.write(180+i-85);
delay(15);
}
}

//rectangle
if(distance>10 && distance<=20){
for(int i=85; i>45; i-=1)
{
servo2.write(i);
servo3.write(160+(0.37*(85-i)));
delay(15);
}
for(int i=45; i>15; i-=1)
{
servo2.write(i);
servo3.write(175+i-45);
delay(15);
}
for(int i=15; i<40; i+=1)
{
servo2.write(i);
servo3.write(145-i+15);
delay(15);
}
for(int i=40; i<85; i+=1)
{
servo2.write(i);
servo3.write(120+(i-35)*0.7);
delay(15);
}
}

//???
if(distance>0 && distance<=10){
for(int i=65; i>30; i-=1)
{
servo2.write(i);
servo3.write(168-(0.5*(65-i)));
delay(15);
}
for(int i=30; i>25; i-=1)
{
servo2.write(i);
servo3.write(150-4.4*(30-i));
delay(15);
}
for(int i=25; i<62.5; i+=1)
{
servo2.write(i);
servo3.write(128+0.4*(62.5-i));
delay(15);
}
for(int i=62.5; i<65; i+=1)
{
servo2.write(i);
servo3.write(143+10*(65-i));
delay(15);
}
}
}
if(zRaw<=470){
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
servo2.write(30);
servo3.write(150);
}

Serial.println(distance);
}

int ReadAxis(int axisPin)
{
long reading = 0;
analogRead(axisPin);
delay(1);
for (int i = 0; i < sampleSize; i++)
{
reading += analogRead(axisPin);
}
return reading/sampleSize;
}

HAOTIAN_HOMEWORK

I make a fortune cat by using a servo and a pressure sensor. The fortune cat waves his hand to gather good luck and fortune. If you press his right hand, he will moves his hand faster.IMG_3141 IMG_3144

 

Code_________________________________________

#include <Servo.h>

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

int sensorPin = 0;
int pre = 0;
int val = 0;

void setup()
{
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop()
{
pre = analogRead(sensorPin);
val = map(pre,0,500,1,10);

for(pos = 30; pos < 160; pos += val) // goes from 30 degrees to 160 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 = 160; pos>=30; pos-=val) // goes from 160 degrees to 30 degrees
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
Serial.println(val);
}

LED’s

 

I used a piezo resistor to control the color of an RGB LED.

CODE:

int knockSensor = 0;

byte val = 0;

int THRESHOLD = 5;

int redPin = 12; // Red LED, connected to digital pin 9
int greenPin =11; // Green LED, connected to digital pin 10
int bluePin =10; // Blue LED, connected to digital pin 11

void setup() {

Serial.begin(9600);
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);

}
void loop() {

val = analogRead(knockSensor);

if (val >= THRESHOLD) {
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, HIGH);

Serial.println(“Knock!”);

}

else{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}

delay(50
);

}

i also made this:

 

//code for fade taken and modified from http://www.instructables.com/id/Fading-RGB-LED-Arduino/?ALLSTEPS
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
int redPin = 9; // Red LED, connected to digital pin 9
int greenPin = 10; // Green LED, connected to digital pin 10
int bluePin = 11; // Blue LED, connected to digital pin 11
int redVal = 255; // Variables to store the values to send to the pins
int greenVal = 1; // Initial values are Red full, Green and Blue off
int blueVal = 1;

int i = 0; // Loop counter
int wait = 1; // 50ms (.05 second) delay; shorten for faster fades
void setup()
{
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600); // …set up the serial ouput on 0004 style
}
}
#define fade(x,y) if (x>y) x–; else if (x<y) x++;

void loop() {

buttonState = digitalRead(buttonPin);
if (buttonState == HIGH){
action();
}
else{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}
}
void action(){

{
i += 1; // Increment counter
if (i < 255) // First phase of fades
{
redVal -= 1; // Red down
greenVal += 1; // Green up
blueVal = 1; // Blue low
}
else if (i < 509) // Second phase of fades
{
redVal = 1; // Red low
greenVal -= 1; // Green down
blueVal += 1; // Blue up
}
else if (i < 763) // Third phase of fades
{
redVal += 1; // Red up
greenVal = 1; // Green low
blueVal -= 1; // Blue down
}
else
{
i = 1;
}

analogWrite(redPin, redVal); // Write current values to LED pins
analogWrite(greenPin, greenVal);
analogWrite(bluePin, blueVal);
}
delay(wait); // Pause for ‘wait’ milliseconds before resuming the loop
}

 

 

HAOTIAN_HOMEWORK

I use the RGB LED light with photoresistors to make the LED change color. The LED can show different colors when you change the amount of light that hits on the photoresistors.

WEEK2

Video:

Pcomp_week2

Arduino code


const int greenLEDPin=9;

const int redLEDPin=10;
const int blueLEDPin=11;

const int redSensorPin=A0;
const int greenSensorPin=A1;
const int blueSensorPin=A2;

int redValue=0;
int greenValue=0;
int blueValue=0;

int redSensorValue=0;
int greenSensorValue=0;
int blueSensorValue=0;

void setup(){
Serial.begin(9600);
pinMode(greenLEDPin,OUTPUT);
pinMode(redLEDPin,OUTPUT);
pinMode(blueLEDPin,OUTPUT);
}

void loop(){
redSensorValue = analogRead(redSensorPin);
delay(5);
greenSensorValue = analogRead(greenSensorPin);
delay(5);
blueSensorValue = analogRead(blueSensorPin);
Serial.print(“Raw Sensor Value \t Red:”);
Serial.print(redSensorValue);
Serial.print(“\t Green:”);
Serial.print(greenSensorValue);
Serial.print(“\t Blue:”);
Serial.println(blueSensorValue);
redValue = redSensorValue/4;
greenValue = greenSensorValue/4;
blueValue = blueSensorValue/4;

Serial.print(“Mapped Sensor Value \t Red:”);
Serial.print(redValue);
Serial.print(“\t Green:”);
Serial.print(greenValue);
Serial.print(“\t Blue:”);
Serial.println(blueValue);

analogWrite(redLEDPin, redValue);
analogWrite(greenLEDPin, greenValue);
analogWrite(blueLEDPin, blueValue);

}


Continue reading