3373| 4
|
[项目] 给失眠者支个‘招’ |
大家都知道睡眠障碍患者普遍都面对到的问题之一是:难以进入放松状态。或因病痛,或思虑过多。本项目试图提供一个思路。从放松方式来入手。来改变人的放松方式。 大家都有在雷雨天入睡快的经历。这个项目就是模拟自然界的雷电交加来模拟一个放松环境。 硬件清单: 1.Arduino Uno 2.DF MP3 3.麦克风模块 4.12V led 5.场效应管IRF520 电路图 代码 [mw_shl_code=applescript,false]/* gada888- 1-18-2020 thunder for Soothing */ #include <SoftwareSerial.h> SoftwareSerial Serial1(10, 11); unsigned char order[4] = {0xAA,0x06,0x00,0xB0}; const int buttonPin = 3; int buttonState = 0; int button = 0; int busyPin = 9; int ledPin = 12; int sensorPin = A1; int sensorValue = 0; int bsy = 0; //***************************************SETUP************************************* void setup () { Serial.begin (115200); Serial1.begin (9600); volume(0x1E);//闊抽噺璁剧疆0x00-0x1E pinMode(buttonPin, INPUT); pinMode(ledPin, OUTPUT); pinMode(busyPin, INPUT); pinMode(buttonPin, INPUT); } //.......................................LOOP................................................ void loop () { Serial.println(""); //Serial.println("Waiting for Button Push"); do { button = digitalRead(buttonPin); } while (button == 0); //Serial.println("Button Hit"); play(0x01);//鎸囧畾鎾斁:0x01-鏂囦欢0001 do{ sensorValue = analogRead (sensorPin); Serial.print(sensorValue); Serial.print(" "); if (sensorValue >= 550) { Serial.println("thunder! "); digitalWrite(ledPin, HIGH); delay (250); } if (sensorValue <= 550) { Serial.println("No sound! "); digitalWrite(ledPin, LOW); delay (250); Serial.println (sensorValue, DEC); } bsy = digitalRead(busyPin); }while (bsy == 0); // zero when sound active //delay (360000); } void play(unsigned char Track) { unsigned char play[6] = {0xAA,0x07,0x02,0x00,Track,Track+0xB3};//0xB3=0xAA+0x07+0x02+0x00,鍗虫渶鍚庝竴浣嶄负鏍¢獙鍜? Serial1.write(play,6); } void volume( unsigned char vol) { unsigned char volume[5] = {0xAA,0x13,0x01,vol,vol+0xBE};//0xBE=0xAA+0x13+0x01,鍗虫渶鍚庝竴浣嶄负鏍¢獙鍜? Serial1.write(volume,5); }[/mw_shl_code] 运行代码 ============== 代码解释: 1.设置开关的目的:不想让项目一通电就播放雷电声。 2.用声音传感值550为测量点。大于这个值就让LED亮。亮的时间控制的0.2秒一次。 ============== 硬件连线 项目展示 |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed