15491浏览
查看: 15491|回复: 22

[互动装置分享]情人节要到了,请爱护一下“我”

[复制链接]
情人节马上就到了,朋友圈即将被秀恩爱攻占,然而情人节的我依然是一只狗做了一个互动装置来表达心里苦
(以及快写完的时候没保存真是气死了)
[互动装置分享]情人节要到了,请爱护一下“我”图3

[互动装置分享]情人节要到了,请爱护一下“我”图1
[互动装置分享]情人节要到了,请爱护一下“我”图2





视频:




材料:
数字触摸传感器  df商城
ADXL345三轴加速度传感器  df商城 SEN0032
Flex单向弯曲传感器  df商城 SEN0086
Arduino Uno  df商场
IO扩展板  df商城
复模硅胶  淘宝
木板,亚克力板  淘宝
doge贴纸  淘宝
绝缘胶带,铝箔纸  五金店
软件:arduino,processing


“我”制作过程:
做这部分的时候忘记记录了,因为传感器老是出问题[哭]……简单的来说就是用激光切割在很多块亚克力板上切了“我”,然后把它们叠在一起,在下面垫一块完整的亚克力板,这样就出现了一个凹槽,先倒一半的硅胶,等它干了贴绝缘胶带,放传感器,在触摸传感器上贴铝箔纸,再贴绝缘胶带,倒另一半硅胶。
注意在边缘留一点空白,硅胶无法和绝缘胶带黏合。


Arduino代码:
  1. #include <Wire.h>
  2. #define DEVICE (0x53)      //ADXL345 device address
  3. #define TO_READ (6)        //num of bytes we are going to read each time (two bytes for each axis)
  4. byte buff[TO_READ] ;        //6 bytes buffer for saving data read from the device
  5. char str[512];              //string buffer to transform data before sending it to the serial port
  6. int regAddress = 0x32;      //first axis-acceleration-data register on the ADXL345
  7. int x, y, z;                //three axis acceleration data
  8. double roll = 0.00, pitch = 0.00;   //Roll & Pitch are the angles which rotate by the axis X and y
  9. //in the sequence of R(x-y-z),more info visit
  10. // <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>
  11. int sensor1 = 0;    // digital sensor
  12. int sensor2= 0;
  13. int sensor3 = 0;
  14. int sensor4 = 0;
  15. int inByte = 0;         // incoming serial byte
  16. int ledPin = 13;                // Connect LED on pin 13, or use the onboard one
  17. int KEY = 3;                 // Connect Touch sensor on Digital Pin 2
  18. int Bend1 = 0;
  19. int Bend2 = 0;
  20. String state = "stop0";
  21. int preState;
  22. void setup(){
  23.   Wire.begin();         // join i2c bus (address optional for master)
  24.   Serial.begin(9600);
  25.   attachInterrupt(0,eventSensor,RISING);
  26.   attachInterrupt(1,eventSensor,RISING);
  27. //Turning on the ADXL345
  28.   writeTo(DEVICE, 0x2D, 0);      
  29.   writeTo(DEVICE, 0x2D, 16);
  30.   writeTo(DEVICE, 0x2D, 8);
  31.   pinMode(ledPin, OUTPUT);      // Set ledPin to output mode
  32.   pinMode(KEY, INPUT);  //Set touch sensor pin to input mode
  33.   pinMode(9, INPUT);
  34.   pinMode(10, INPUT);
  35.   pinMode(11, INPUT);
  36. }
  37. void loop(){
  38.   sensor1 = digitalRead(KEY);
  39.   sensor2 = digitalRead(9);
  40.   sensor3 = digitalRead(10);
  41.   sensor4 = digitalRead(11);
  42.   Bend1 = analogRead(3);
  43.   Bend2 = analogRead(2);  
  44.   readFrom(DEVICE, regAddress, TO_READ, buff); //read the acceleration data from the ADXL345
  45.                                               //each axis reading comes in 10 bit resolution, ie 2 bytes.  Least Significat Byte first!!
  46.                                               //thus we are converting both bytes in to one int
  47.   x = (((int)buff[1]) << 8) | buff[0];   
  48.   y = (((int)buff[3])<< 8) | buff[2];
  49.   z = (((int)buff[5]) << 8) | buff[4];
  50.   Serial.println(sensor3);
  51.   //we send the x y z values as a string to the serial port
  52.   //Serial.print("The acceleration info of x, y, z are:");
  53.   sprintf(str, "%d %d %d %d %d\t",x, y, z, Bend1,Bend2);  
  54.   Serial.print(str);
  55.   Serial.println(state);
  56.   if (state == "play")
  57.   {
  58.     delay(2000);
  59.     state = "stop";
  60.   }
  61.   //It appears that delay is needed in order not to clog the port
  62.   delay(50);
  63. }
  64. //---------------- Functions
  65. //Writes val to address register on device
  66. void writeTo(int device, byte address, byte val) {
  67.   Wire.beginTransmission(device); //start transmission to device
  68.   Wire.write(address);        // send register address
  69.   Wire.write(val);        // send value to write
  70.   Wire.endTransmission(); //end transmission
  71. }
  72. //reads num bytes starting from address register on device in to buff array
  73. void readFrom(int device, byte address, int num, byte buff[]) {
  74.   Wire.beginTransmission(device); //start transmission to device
  75.   Wire.write(address);        //sends address to read from
  76.   Wire.endTransmission(); //end transmission
  77.     Wire.beginTransmission(device); //start transmission to device
  78.   Wire.requestFrom(device, num);    // request 6 bytes from device
  79.   int i = 0;
  80.   while(Wire.available())    //device may send less than requested (abnormal)
  81.   {
  82.     buff = Wire.read(); // receive a byte
  83.     i++;
  84.   }
  85.   Wire.endTransmission(); //end transmission
  86. }
  87. //calculate the Roll&Pitch
  88. void RP_calculate(){
  89.   double x_Buff = float(x);
  90.   double y_Buff = float(y);
  91.   double z_Buff = float(z);
  92.   roll = atan2(y_Buff , z_Buff) * 57.3;
  93.   pitch = atan2((- x_Buff) , sqrt(y_Buff * y_Buff + z_Buff * z_Buff)) * 57.3;
  94. }
  95. void eventSensor()
  96. {
  97.   state = "play";
  98. }
  99. Processing代码:
  100. import ddf.minim.*;
  101. import processing.serial.*;
  102. Serial myPort;  // The serial port
  103. Minim minim;
  104. AudioPlayer[] touchplayer;
  105. AudioPlayer[] bendplayer;
  106. AudioPlayer[] shakeplayer;
  107. PImage img1;// background
  108. PImage img2;//touch sensor
  109. PImage img3;//bend sensor
  110. PImage img4;//accel sensor
  111. String myString = null;
  112. int lf = 10;    // Linefeed in ASCII
  113. int x_cur = 0;   
  114. int x_pre = x_cur; // for accel sensor
  115. int z_cur = 0;
  116. int z_pre = z_cur; // for accel sensor
  117. int bend1=0;
  118. int bend2=0;
  119. int index1=0; // for touch sensor
  120. int index2=0; // for bend sensor
  121. int index3=0; // for accel sensor
  122. void setup() {
  123.   size(1440,900); //size of a MacBook
  124.   printArray(Serial.list()); // List all the available serial ports
  125.   myPort = new Serial(this, Serial.list()[3], 9600); // Open the port you are using at the rate you want:
  126.   myPort.clear();
  127.   // Throw out the first reading, in case we started reading
  128.   // in the middle of a string from the sender.
  129.   myString = myPort.readStringUntil(lf);
  130.   myString = null;
  131.   minim= new Minim(this);
  132.   touchplayer=new AudioPlayer[8];
  133.   touchplayer[0]=minim.loadFile("touch.wav");
  134.   touchplayer[1]=minim.loadFile("touch02.wav");
  135.   touchplayer[2]=minim.loadFile("touch03.wav");
  136.   touchplayer[3]=minim.loadFile("touch04.wav");
  137.   touchplayer[4]=minim.loadFile("touch05.wav");
  138.   touchplayer[5]=minim.loadFile("touch06.wav");
  139.   touchplayer[6]=minim.loadFile("touch07.wav");
  140.   touchplayer[7]=minim.loadFile("touch08.wav"); //audio for touch sensors
  141.   for (int i=0;i<8;i++){
  142.     touchplayer.loop();
  143.     touchplayer.mute();
  144.   }       //loop and mute all the audio for touch sensors
  145.   bendplayer=new AudioPlayer[1];
  146.   bendplayer[0]=minim.loadFile("howl.wav"); // audio for bend sensors
  147.   bendplayer[0].loop();
  148.   bendplayer[0].mute(); //loop and mute all the audio for bend sensors
  149.   shakeplayer= new AudioPlayer[1];
  150.   shakeplayer[0]=minim.loadFile("shake01.wav"); //audio for shake sensors
  151.   shakeplayer[0].loop();
  152.   shakeplayer[0].mute(); //loop and mute all the audio for shake sensors
  153.   img1=loadImage("background1.png");
  154.   img2=loadImage("background2.png");
  155.   img3=loadImage("bend.png");
  156.   img4=loadImage("shake.png"); //load all the backgrounds
  157. }
  158. void draw() {
  159.   while (myPort.available() > 0) {
  160.     myString = myPort.readStringUntil(lf);
  161.     if(myString != null) {
  162.       String[] list = split(myString, "\t");
  163.       if(list.length == 2){
  164.         String state = list[1].replaceAll("[^a-zA-Z]","");
  165.         if (state.equals("stop")==true){
  166.           touchplayer[index1].rewind();
  167.           touchplayer[index1].mute();
  168.           image(img1,0,0);
  169.           if(index1<6){
  170.             index1++;
  171.           } else{
  172.             index1=0;
  173.           }
  174.         } else{
  175.           println("is touching");
  176.           touchplayer[index1].unmute();
  177.           image(img2,0,0);
  178.         }
  179.         int[] accel=int(split(list[0], " ")); //accelerator=[x,y,z,bend1,bend2];  
  180.         if(accel.length==5){  
  181.           x_cur = accel[1];
  182.           z_cur = accel[2];
  183.           bend1 = accel[3];
  184.           bend2 = accel[4];
  185.           println(bend1);
  186.           println(bend2);
  187.           if(bend1>345 ||bend2>=675){      
  188.             bendplayer[index2].unmute();
  189.             image(img3,0,0);
  190.             println("is bended");
  191.           } else{
  192.             bendplayer[index2].rewind();
  193.             bendplayer[index2].mute();
  194.           }
  195.          if(abs(x_pre - x_cur) > 70 ||abs(z_pre - z_cur)>70){ // two axixs detect
  196.            shakeplayer[0].unmute();
  197.            println("is shaking");
  198.            image(img4,0,0);
  199.          } else{
  200.            shakeplayer[0].rewind();
  201.            shakeplayer[0].mute();
  202.          }
  203.        }      
  204.      }
  205.     x_pre = x_cur;
  206.     z_pre = z_cur;
  207.     }
  208.   }
  209. }
复制代码


这个装置的灵感来源于日本的一个叫“ah”的互动文字装置:https://vimeo.com/52555492

最后,祝大家情人节快乐~单身狗也可以自己找乐~

TB1m9T4HpXXXXauXXXXXXXXXXXX___0-item_pic.png

iooops  中级技匠

发表于 2017-2-5 20:34:04

沙发 = =
回复

使用道具 举报

iooops  中级技匠

发表于 2017-2-5 20:34:10

板凳
回复

使用道具 举报

iooops  中级技匠

发表于 2017-2-5 20:34:14

地板
回复

使用道具 举报

iooops  中级技匠

发表于 2017-2-5 20:36:21

哇真是666 666 666
回复

使用道具 举报

iooops  中级技匠

发表于 2017-2-5 20:38:13

怎么感觉单身狗真的嚎惨 = =
回复

使用道具 举报

Ash  管理员

发表于 2017-2-6 09:58:17

掰弯的效果 哈哈哈哈哈
回复

使用道具 举报

zbl  中级技匠

发表于 2017-2-6 10:15:47

ahahah,好好玩的样子
回复

使用道具 举报

luna  初级技神

发表于 2017-2-6 11:31:15

zbl 发表于 2017-2-6 10:15
ahahah,好好玩的样子

情人节~微信见
回复

使用道具 举报

nicho  中级技匠

发表于 2017-2-6 21:58:32

赞!
回复

使用道具 举报

阿斗  高级技师

发表于 2017-2-7 09:36:37

你们还有六天的时间考虑,是和我在一起,还是做一条狗。
茄子黄瓜或者我,你选一个。
回复

使用道具 举报

hnyzcj  版主

发表于 2017-2-7 15:17:56

阿斗 发表于 2017-2-7 09:36
你们还有六天的时间考虑,是和我在一起,还是做一条狗。
茄子黄瓜或者我,你选一个。 ...

你想多了
回复

使用道具 举报

hnyzcj  版主

发表于 2017-2-7 15:18:10

楼主这个赞
回复

使用道具 举报

kaka  高级技师

发表于 2017-2-7 15:30:43

没看懂是什么?视频刷不出来
回复

使用道具 举报

阿斗  高级技师

发表于 2017-2-8 09:27:17


感受滑稽之力
回复

使用道具 举报

luna  初级技神

发表于 2017-2-8 10:23:00

阿斗 发表于 2017-2-7 09:36
你们还有六天的时间考虑,是和我在一起,还是做一条狗。
茄子黄瓜或者我,你选一个。 ...

杀手锏无效~~还是自己做个脱单神奇吧:lol
回复

使用道具 举报

luna  初级技神

发表于 2017-2-8 10:23:40

kaka 发表于 2017-2-7 15:30
没看懂是什么?视频刷不出来

你复制一下视频地址,然后去优酷看啊~
回复

使用道具 举报

创客火  初级技师

发表于 2017-2-10 14:56:15

好玩:lol
回复

使用道具 举报

weiking  初级技师

发表于 2017-2-14 15:27:10

太牛了,向你学习!
回复

使用道具 举报

糖醋花生  高级技师

发表于 2022-7-5 18:58:34

阿斗 发表于 2017-2-7 09:36
你们还有六天的时间考虑,是和我在一起,还是做一条狗。
茄子黄瓜或者我,你选一个。 ...

巫师,麻瓜伏地魔,你选一个
回复

使用道具 举报

派大星ym  初级技匠

发表于 2022-8-6 21:34:36

牛牛牛牛牛
回复

使用道具 举报

12下一页
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail