Ver código fonte

Initial commit

master
The Dod 2 anos atrás
commit
5752a5d04f
4 arquivos alterados com 67 adições e 0 exclusões
  1. 4
    0
      README.md
  2. BIN
      flora-mic2color.fzz
  3. 63
    0
      flora-mic2color.ino
  4. BIN
      flora-mic2color_bb.png

+ 4
- 0
README.md Ver arquivo

@@ -0,0 +1,4 @@
1
+Microphone's Low/Mid/High affect the R/G/B of an [Adafruit Flora](https://www.adafruit.com/product/659)'s builtin LED.
2
+
3
+<video controls=""><source src="https://zzzen.com/kraftz/2020-04-15%20-%20mic2clor.webm" type="video/webm"></video>
4
+

BIN
flora-mic2color.fzz Ver arquivo


+ 63
- 0
flora-mic2color.ino Ver arquivo

@@ -0,0 +1,63 @@
1
+#include <Adafruit_NeoPixel.h>
2
+#ifdef __AVR__
3
+#include <avr/power.h>
4
+#endif
5
+
6
+#define NUMLEDS 1
7
+#define LEDPIN 8
8
+#define MICPIN A9
9
+#define FAKEVCCPIN 6
10
+
11
+
12
+Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMLEDS, LEDPIN, NEO_GRB + NEO_KHZ800);
13
+
14
+#define BUFFSIZE 115
15
+#define AVGSIZE 23
16
+
17
+int rawBuff[BUFFSIZE];
18
+int notHighBuff[BUFFSIZE];
19
+int lowBuff[BUFFSIZE];
20
+int index, minLow, maxLow, minMid, maxMid, minHigh, maxHigh;
21
+
22
+#define RAWLOW(i) (lowBuff[i])
23
+#define RAWMID(i) (notHighBuff[i]-lowBuff[i])
24
+#define RAWHIGH(i) (rawBuff[i]-notHighBuff[i])
25
+
26
+#define NORMLOW(i) constrain(map(RAWLOW(i), minLow, maxLow, 0, 255), 0, 255)
27
+#define NORMMID(i) constrain(map(RAWMID(i), minMid, maxMid, 0, 255), 0, 255)
28
+#define NORMHIGH(i) constrain(map(RAWHIGH(i), minHigh, maxHigh, 0, 255), 0, 255)
29
+
30
+void setup() {
31
+  pinMode(FAKEVCCPIN, OUTPUT);
32
+  digitalWrite(FAKEVCCPIN, HIGH);
33
+  index = 0;
34
+  strip.begin();
35
+  strip.show(); // Initialize all pixels to 'off'
36
+  for (int i = 0; i < BUFFSIZE; i++) {
37
+    rawBuff[i] = notHighBuff[i] = lowBuff[i] = 512;
38
+  }
39
+}
40
+
41
+void loop() {
42
+  rawBuff[index] = analogRead(MICPIN);
43
+  notHighBuff[index] = 0;
44
+  int nextIndex = (index + 1) % BUFFSIZE;
45
+  for (int i = nextIndex + BUFFSIZE - AVGSIZE; i % BUFFSIZE != nextIndex; i++) {
46
+    notHighBuff[index] += rawBuff[i % BUFFSIZE];
47
+  }
48
+  notHighBuff[index] /= AVGSIZE;
49
+  lowBuff[index] = (notHighBuff[index] + notHighBuff[(index + BUFFSIZE - AVGSIZE) % BUFFSIZE]) / 2;
50
+  minLow = minMid = minHigh = 1024;
51
+  maxLow = maxMid = maxHigh = -1;
52
+  for (int i = 0; i < BUFFSIZE; i++) {
53
+    minLow =   min(minLow, RAWLOW(i));
54
+    minMid =   min(minMid, RAWMID(i));
55
+    minHigh =  min(minHigh, RAWHIGH(i));
56
+    maxLow =   max(maxLow, RAWLOW(i));
57
+    maxMid =   max(maxMid, RAWMID(i));
58
+    maxHigh =  max(maxHigh, RAWHIGH(i));
59
+  }
60
+  strip.setPixelColor(0, strip.Color(NORMHIGH(index), NORMMID(index), NORMLOW(index)));
61
+  strip.show();
62
+  index = nextIndex;
63
+};

BIN
flora-mic2color_bb.png Ver arquivo


Carregando…
Cancelar
Salvar