[互动装置分享]情人节要到了,请爱护一下“我”
情人节马上就到了,朋友圈即将被秀恩爱攻占,然而情人节的我依然是一只狗做了一个互动装置来表达心里苦(以及快写完的时候没保存真是气死了)
视频:
https://v.youku.com/v_show/id_XMjQ5NzM0MTk1Mg==.html
材料:
数字触摸传感器df商城
ADXL345三轴加速度传感器df商城 SEN0032
Flex单向弯曲传感器df商城 SEN0086
Arduino Unodf商场
IO扩展板df商城
复模硅胶淘宝
木板,亚克力板淘宝
doge贴纸淘宝
绝缘胶带,铝箔纸五金店
软件:arduino,processing
“我”制作过程:
做这部分的时候忘记记录了,因为传感器老是出问题[哭]……简单的来说就是用激光切割在很多块亚克力板上切了“我”,然后把它们叠在一起,在下面垫一块完整的亚克力板,这样就出现了一个凹槽,先倒一半的硅胶,等它干了贴绝缘胶带,放传感器,在触摸传感器上贴铝箔纸,再贴绝缘胶带,倒另一半硅胶。
注意在边缘留一点空白,硅胶无法和绝缘胶带黏合。
Arduino代码:
#include <Wire.h>
#define DEVICE (0x53) //ADXL345 device address
#define TO_READ (6) //num of bytes we are going to read each time (two bytes for each axis)
byte buff ; //6 bytes buffer for saving data read from the device
char str; //string buffer to transform data before sending it to the serial port
int regAddress = 0x32; //first axis-acceleration-data register on the ADXL345
int x, y, z; //three axis acceleration data
double roll = 0.00, pitch = 0.00; //Roll & Pitch are the angles which rotate by the axis X and y
//in the sequence of R(x-y-z),more info visit
// <a href="https://www.dfrobot.com/wiki/index.php?title=How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing#Introduction" target="_blank">https://www.dfrobot.com/wiki/ind ... ensing#Introduction</a>
int sensor1 = 0; // digital sensor
int sensor2= 0;
int sensor3 = 0;
int sensor4 = 0;
int inByte = 0; // incoming serial byte
int ledPin = 13; // Connect LED on pin 13, or use the onboard one
int KEY = 3; // Connect Touch sensor on Digital Pin 2
int Bend1 = 0;
int Bend2 = 0;
String state = "stop0";
int preState;
void setup(){
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600);
attachInterrupt(0,eventSensor,RISING);
attachInterrupt(1,eventSensor,RISING);
//Turning on the ADXL345
writeTo(DEVICE, 0x2D, 0);
writeTo(DEVICE, 0x2D, 16);
writeTo(DEVICE, 0x2D, 8);
pinMode(ledPin, OUTPUT); // Set ledPin to output mode
pinMode(KEY, INPUT);//Set touch sensor pin to input mode
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
}
void loop(){
sensor1 = digitalRead(KEY);
sensor2 = digitalRead(9);
sensor3 = digitalRead(10);
sensor4 = digitalRead(11);
Bend1 = analogRead(3);
Bend2 = analogRead(2);
readFrom(DEVICE, regAddress, TO_READ, buff); //read the acceleration data from the ADXL345
//each axis reading comes in 10 bit resolution, ie 2 bytes.Least Significat Byte first!!
//thus we are converting both bytes in to one int
x = (((int)buff) << 8) | buff;
y = (((int)buff)<< 8) | buff;
z = (((int)buff) << 8) | buff;
Serial.println(sensor3);
//we send the x y z values as a string to the serial port
//Serial.print("The acceleration info of x, y, z are:");
sprintf(str, "%d %d %d %d %d\t",x, y, z, Bend1,Bend2);
Serial.print(str);
Serial.println(state);
if (state == "play")
{
delay(2000);
state = "stop";
}
//It appears that delay is needed in order not to clog the port
delay(50);
}
//---------------- Functions
//Writes val to address register on device
void writeTo(int device, byte address, byte val) {
Wire.beginTransmission(device); //start transmission to device
Wire.write(address); // send register address
Wire.write(val); // send value to write
Wire.endTransmission(); //end transmission
}
//reads num bytes starting from address register on device in to buff array
void readFrom(int device, byte address, int num, byte buff[]) {
Wire.beginTransmission(device); //start transmission to device
Wire.write(address); //sends address to read from
Wire.endTransmission(); //end transmission
Wire.beginTransmission(device); //start transmission to device
Wire.requestFrom(device, num); // request 6 bytes from device
int i = 0;
while(Wire.available()) //device may send less than requested (abnormal)
{
buff = Wire.read(); // receive a byte
i++;
}
Wire.endTransmission(); //end transmission
}
//calculate the Roll&Pitch
void RP_calculate(){
double x_Buff = float(x);
double y_Buff = float(y);
double z_Buff = float(z);
roll = atan2(y_Buff , z_Buff) * 57.3;
pitch = atan2((- x_Buff) , sqrt(y_Buff * y_Buff + z_Buff * z_Buff)) * 57.3;
}
void eventSensor()
{
state = "play";
}
Processing代码:
import ddf.minim.*;
import processing.serial.*;
Serial myPort;// The serial port
Minim minim;
AudioPlayer[] touchplayer;
AudioPlayer[] bendplayer;
AudioPlayer[] shakeplayer;
PImage img1;// background
PImage img2;//touch sensor
PImage img3;//bend sensor
PImage img4;//accel sensor
String myString = null;
int lf = 10; // Linefeed in ASCII
int x_cur = 0;
int x_pre = x_cur; // for accel sensor
int z_cur = 0;
int z_pre = z_cur; // for accel sensor
int bend1=0;
int bend2=0;
int index1=0; // for touch sensor
int index2=0; // for bend sensor
int index3=0; // for accel sensor
void setup() {
size(1440,900); //size of a MacBook
printArray(Serial.list()); // List all the available serial ports
myPort = new Serial(this, Serial.list(), 9600); // Open the port you are using at the rate you want:
myPort.clear();
// Throw out the first reading, in case we started reading
// in the middle of a string from the sender.
myString = myPort.readStringUntil(lf);
myString = null;
minim= new Minim(this);
touchplayer=new AudioPlayer;
touchplayer=minim.loadFile("touch.wav");
touchplayer=minim.loadFile("touch02.wav");
touchplayer=minim.loadFile("touch03.wav");
touchplayer=minim.loadFile("touch04.wav");
touchplayer=minim.loadFile("touch05.wav");
touchplayer=minim.loadFile("touch06.wav");
touchplayer=minim.loadFile("touch07.wav");
touchplayer=minim.loadFile("touch08.wav"); //audio for touch sensors
for (int i=0;i<8;i++){
touchplayer.loop();
touchplayer.mute();
} //loop and mute all the audio for touch sensors
bendplayer=new AudioPlayer;
bendplayer=minim.loadFile("howl.wav"); // audio for bend sensors
bendplayer.loop();
bendplayer.mute(); //loop and mute all the audio for bend sensors
shakeplayer= new AudioPlayer;
shakeplayer=minim.loadFile("shake01.wav"); //audio for shake sensors
shakeplayer.loop();
shakeplayer.mute(); //loop and mute all the audio for shake sensors
img1=loadImage("background1.png");
img2=loadImage("background2.png");
img3=loadImage("bend.png");
img4=loadImage("shake.png"); //load all the backgrounds
}
void draw() {
while (myPort.available() > 0) {
myString = myPort.readStringUntil(lf);
if(myString != null) {
String[] list = split(myString, "\t");
if(list.length == 2){
String state = list.replaceAll("[^a-zA-Z]","");
if (state.equals("stop")==true){
touchplayer.rewind();
touchplayer.mute();
image(img1,0,0);
if(index1<6){
index1++;
} else{
index1=0;
}
} else{
println("is touching");
touchplayer.unmute();
image(img2,0,0);
}
int[] accel=int(split(list, " ")); //accelerator=;
if(accel.length==5){
x_cur = accel;
z_cur = accel;
bend1 = accel;
bend2 = accel;
println(bend1);
println(bend2);
if(bend1>345 ||bend2>=675){
bendplayer.unmute();
image(img3,0,0);
println("is bended");
} else{
bendplayer.rewind();
bendplayer.mute();
}
if(abs(x_pre - x_cur) > 70 ||abs(z_pre - z_cur)>70){ // two axixs detect
shakeplayer.unmute();
println("is shaking");
image(img4,0,0);
} else{
shakeplayer.rewind();
shakeplayer.mute();
}
}
}
x_pre = x_cur;
z_pre = z_cur;
}
}
}
这个装置的灵感来源于日本的一个叫“ah”的互动文字装置:https://vimeo.com/52555492
最后,祝大家情人节快乐~单身狗也可以自己找乐~
沙发 = = {:5_161:} 板凳 地板 哇真是666 666 666{:5_180:} 怎么感觉单身狗真的嚎惨 = = {:5_194:} 掰弯的效果 哈哈哈哈哈{:5_148:} ahahah,好好玩的样子{:5_179:} zbl 发表于 2017-2-6 10:15
ahahah,好好玩的样子
情人节~微信见 {:5_148:}赞! 你们还有六天的时间考虑,是和我在一起,还是做一条狗。
茄子黄瓜或者我,你选一个。 阿斗 发表于 2017-2-7 09:36
你们还有六天的时间考虑,是和我在一起,还是做一条狗。
茄子黄瓜或者我,你选一个。 ...
你想多了 楼主这个赞 没看懂是什么?视频刷不出来 hnyzcj 发表于 2017-2-7 15:17
你想多了
{:5_173:}感受滑稽之力 阿斗 发表于 2017-2-7 09:36
你们还有六天的时间考虑,是和我在一起,还是做一条狗。
茄子黄瓜或者我,你选一个。 ...
{:5_169:} 杀手锏无效~~还是自己做个脱单神奇吧:lol kaka 发表于 2017-2-7 15:30
没看懂是什么?视频刷不出来
你复制一下视频地址,然后去优酷看啊~ 好玩:lol 太牛了,向你学习! 阿斗 发表于 2017-2-7 09:36
你们还有六天的时间考虑,是和我在一起,还是做一条狗。
茄子黄瓜或者我,你选一个。 ...
巫师,麻瓜伏地魔,你选一个 牛牛牛牛牛
页:
[1]
2