-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelettroNoise.ino
More file actions
74 lines (62 loc) · 1.65 KB
/
elettroNoise.ino
File metadata and controls
74 lines (62 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Coded by Pietro Squilla
// Il presente sketch monitora il rumore elettromagnetico e lo sfrutta per generare byte casuali
#include "Arduino_LED_Matrix.h"
// per estrarre il rumore
const int OPAMP_OUT_PIN = A0;
const int SOGLIA_RUMORE = 300; // valore da 0 a 1023
int counter = 0;
int noiseValue = 0;
// per plot sulla matrice di led
ArduinoLEDMatrix matrix;
int i, j = 0;
bool stop = false;
uint8_t frame[8][12] = {
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0}
};
void setup(){
Serial.begin(9600);
matrix.begin();
// risoluzione dell'opamp a 10 bit (valori da 0 a 1023)
analogReadResolution(10);
}
// funzione per leggere il rumore elettronico
int generateNoise(){
return analogRead(OPAMP_OUT_PIN);
}
void loop(){
noiseValue = generateNoise();
//Serial.println((String)"noise: " + noiseValue); // print di debug per calibrare la soglia
// incrementa la variabile aleatoria
counter++;
if(counter > 255){
counter = 0;
}
// se il rumore supera la soglia leggi la variabile
if(noiseValue > SOGLIA_RUMORE){
Serial.println(counter);
// controllo matrice di led per monitorare senza seriale
if(!stop){
frame[i][j] = 1;
matrix.renderBitmap(frame, 8, 12);
// conta i numeri trovati sulla matrice di led
i++;
if(i >= 8){
j++;
i = 0;
}
}
// se sono finiti i led non aggiornare più la matrice
if(j >= 12){
stop = true;
}
delay(1000);
}
//delay(100);
}