# arduino 20221215
[TOC]
## 狀態圖
https://plantuml.com/zh/state-diagram
## 醒腦鐘
https://ushangz.wordpress.com/2022/12/08/%e6%9c%9f%e6%9c%ab%e6%8f%90%e6%a1%88-%e9%86%92%e8%85%a6%e9%90%98/
[][][][][][][]
測試// 開機 3000 => 鈴響的模式
定時
鈴響
按照指示按順序的按鈕 X 7
解除鈴響
processing 做軟體介面的模擬
按鈕 的 lib: ControlP5
聲音 的 lib: Sound
### 狀態圖
```plantuml
[*] --> 定時
定時:輸入鬧鐘時間
[*] --> 鈴響
定時 --> [*]
鈴響 : 判斷時間到,開始撥放聲音
按照指示按順序的按鈕:輸入正確順序的按鈕
鈴響 -> 按照指示按順序的按鈕
按照指示按順序的按鈕->解除鈴響
解除鈴響:關閉撥放聲音
解除鈴響 --> [*]
```
### processing 範例
```processing
import controlP5.*;
ControlP5 cp5;
import processing.sound.*;
SoundFile soundfile;
String click ="";
void setup() {
size(640, 360);
background(255);
cp5 = new ControlP5(this);
cp5.addButton("Btn_1")
.setValue(0)
.setPosition(100, 100)
.setSize(200, 19)
;
cp5.addButton("Btn_2")
.setValue(0)
.setPosition(100, 120)
.setSize(200, 19)
;
cp5.addButton("Btn_3")
.setValue(0)
.setPosition(100, 140)
.setSize(200, 19)
;
cp5.addButton("Btn_4")
.setValue(0)
.setPosition(100, 160)
.setSize(200, 19)
;
cp5.addButton("Btn_5")
.setValue(0)
.setPosition(100, 180)
.setSize(200, 19)
;
cp5.addButton("Btn_6")
.setValue(0)
.setPosition(100, 200)
.setSize(200, 19)
;
cp5.addButton("Btn_7")
.setValue(0)
.setPosition(100, 220)
.setSize(200, 19)
;
soundfile = new SoundFile(this, "vibraphon.aiff");
soundfile.loop();
}
void draw() {
//println(frameCount);
if (frameCount<10)click="";
background(0);
text("click:"+click, 50, 50);
if (click.indexOf("1234567")>-1) {
soundfile.stop();
}
}
void mousePressed() {
//soundfile.stop();
}
public void Btn_1(int theValue) {
click+="1";
}
public void Btn_2(int theValue) {
click+="2";
}
public void Btn_3(int theValue) {
click+="3";
}
public void Btn_4(int theValue) {
click+="4";
}
public void Btn_5(int theValue) {
click+="5";
}
public void Btn_6(int theValue) {
click+="6";
}
public void Btn_7(int theValue) {
click+="7";
}
```
## 音閱
https://tjuku1491.blogspot.com/2022/12/blog-post.html
人<作品(觸發)<撥放音樂<機構運作<人
### 狀態描述?
### 造型: DIY 藍芽喇吧
3d printer=> 新的造型 給 聽障人士
### 功能
processing fft =>
#### 視覺
processing fft =>
#### 觸覺
? processing => arduino => 馬達 motor
### processing 範例
```processing
import processing.sound.*;
SoundFile sample;
FFT fft;
int bands = 128;
float smoothingFactor = 0.2;
float[] sum = new float[bands];
int scale = 5;
float barWidth;
public void setup() {
size(640, 360);
background(255);
barWidth = width/float(bands);
sample = new SoundFile(this, "beat.aiff");
sample.loop();
fft = new FFT(this, bands);
fft.input(sample);
}
public void draw() {
background(125, 255, 125);
fill(255, 0, 150);
noStroke();
fft.analyze();
for (int i = 0; i < bands; i++) {
sum[i] += (fft.spectrum[i] - sum[i]) * smoothingFactor;
rect(i*barWidth, height, barWidth, -sum[i]*height*scale);
ellipse(width/2, height/2, -sum[i]*height*scale, -sum[i]*height*scale);
}
}
```
### 狀態圖
```plantuml
[*] --> 裝置播放音樂
裝置播放音樂->等待人:人可以互動
停止播放音樂 --> [*]
```
## 其他