Emotion Machine

17

所需準備材料:

1. arduino LED光圈x1

2. arduino聲音感測器x1

3. 線路x8

4. USB連接線

5. 一個枕頭或是容器(可要可不要,裝飾外觀用)

做這個機器的主要目的:

現代人總是缺乏一個能夠讓自己紓壓的管道,所以將許多的壓力放置於心中,這些都是不健康的生活型態,我希望我的機器能夠讓更多人不要累積那麼多的不舒服情緒在自己的心中。

使用方法:

將機器的連接線連上電腦的程式碼,LED光泉便會開始閃爍呈現繞圈形式的光,一開始是平靜的綠色,隨著它所聽到的聲音越來越大也會改變它的顏色和旋轉速度,最後便會成極速旋轉的紅色,傷心之人可以朝著它法謝自己內心的情緒,機器就像一個知心朋友般的聆聽你說話。

Step 1: 程式碼

#include

Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, 6);

const int micPin = A2; void setup() { Serial.begin(9600); strip.begin(); strip.setBrightness(32); strip.show();

void loop() { cureLamp(120, 50); }

void cureLamp(int activeBase, int runDelay) { char state = 'a'; int red = 0; int green = 0; int gRest = 0;

int timeRest = 0; int runDelayRest;

unsigned long ms; unsigned long restTimer; unsigned long sleepTimer;

int cnt = 0; int vin; int vmin = 10000; int vmax = 0; int diff;

sleepTimer = restTimer = millis(); while (true) {

vin = analogRead(micPin); if (vin > vmax) vmax = vin; if (vin < vmin) vmin = vin;

cnt ++; if (cnt >= 100) { diff = vmax - vmin; if (diff > 255) diff = 255;

red -= 10; if (red <= diff) red = diff; green = 255 - red;

if (diff >= activeBase) { state = 'a'; restTimer = millis(); }

Serial.print(String("max=") + vmax + " min=" + vmin + " " + " state=" + state + " diff="+ diff); for (int i = 0; i < (diff / 5); i++) Serial.print('*'); Serial.println("");

vmax = 0; vmin = 10000; cnt = 0; }

ms = millis(); if (state == 'a') { int showCureDelay = map(red, 0, 255, runDelay, 20); showCure(red, green, 0, showCureDelay);

if (ms - restTimer > 3000) { state = 'b'; gRest = green; timeRest = 1; runDelayRest = map(red, 0, 255, runDelay, 20); sleepTimer = ms; } }

else if (state == 'b') { if (ms - sleepTimer > timeRest) { sleepTimer = ms; gRest--; timeRest++; if (gRest == 0) state = 'c'; } showCure(0, gRest, 0, runDelayRest); }

else if (state == 'c') { if (ms - sleepTimer > 3000) { if ((exp(sin(ms / 2000.0 * PI)) - 0.36787944) * 108.0 < 5) state = 'd'; } }

else { int val = (exp(sin(ms / 2000.0 * PI)) - 0.36787944) * 108.0; showAll(0, 0, val); } } }

void showCure(int r, int g, int b, int runDelay) { static int runPos = 0; static unsigned long runTimer;

if (millis() - runTimer > runDelay) { runPos++; if (runPos >= strip.numPixels()) runTimer = millis(); }

strip.clear(); int pos = runPos; for (int i = 0; i < 1 + (r / 20); i++) { strip.setPixelColor(pos, r, g, b); pos++; if (pos >= strip.numPixels()) pos = 0; } strip.show(); }

void showAll(int r, int g, int b) { for (int i = 0; i < strip.numPixels(); i++) { strip.setPixelColor(i, r, g, b); } strip.show(); }

Step 2: 線路圖

Step 3: 裝飾

Step 4: 成果影片

Share

    Recommendations

    • Pets Challenge

      Pets Challenge
    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest
    • Sensors Contest

      Sensors Contest

    Discussions