-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalpha.cpp
More file actions
125 lines (97 loc) · 2.59 KB
/
alpha.cpp
File metadata and controls
125 lines (97 loc) · 2.59 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
//////////////////|||\\\\\\\\\\\\\\\\\\\\
||| Easyino - Education Official Sketch |||
\\\\\\\\\\\\\\\\\\|||////////////////////
Easyino.cpp - Library for using our inboard components in the best way
Created by Federico Longhin, Mattia Pilotto, Edoardo Baggio 03 April, 2020.
Manteined by Federico Longhin & Mattia Pilotto.
V 0.3
*/
#include "alpha.h"
#include "Arduino.h"
#include "settings.h"
#include <EEPROM.h>
#include <SPI.h>
int modello_scheda = 0;
Easy::Easy(int sc) {
modello_scheda = sc;
pinMode(led_R, OUTPUT);
pinMode(led_G, OUTPUT);
pinMode(led_B, OUTPUT);
pinMode(8, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(A4, INPUT_PULLUP);
pinMode(A5, INPUT_PULLUP);
}
void Easy::aspetta( int d)
{
delay(d);
}
void Easy::boot() {
tone(3, 988, 50);
delay(100);
tone(3, 1976, 50);
delay(100);
tone(3, 3951, 50);
delay(100);
}
//led RGB
void Easy::accendi( int r, int g, int b)
{
analogWrite(led_R, r);
analogWrite(led_G, g);
analogWrite(led_B, b);
}
void Easy::accendi(byte colore)
{
#define n_colori 6 //ci sono 3 colori salvati
// char* lista_colori[] = {"ROSSO", "VERDE", "BLU", "GIALLO", "BIANCO", "ROSA"};
int ton_rosso[] = {0,255, 0, 0, 255, 255, 255};
int ton_giallo[] = {0,0, 255, 0, 255, 255, 0};
int ton_blu[] = {0, 0,0, 255, 0, 255, 255};
analogWrite(led_R, ton_rosso[colore]);
analogWrite(led_G, ton_giallo[colore]);
analogWrite(led_B, ton_blu[colore]);
}
//microfono
bool Easy::ascolta() {
#define buffer_mic 10
if (analogRead(microfono) > (soglia_microfono + buffer_mic) || analogRead(microfono) < (soglia_microfono - buffer_mic)) {
return true;
}
else return false;
}
void Easy::calibraMicrofono(int so) {
soglia_microfono = so;
}
//fotoresistenza
int livello_luce_salvato;
void Easy::registraLuce() {
livello_luce_salvato = analogRead(fotoresistenza);
}
int Easy::livelloLuce() {
return analogRead(fotoresistenza);
}
//buzz
void Easy::suona(int nota, int durata) {
if (nota != "PAUSA") {
tone(buzz, nota, durata);
}
}
void Easy::suonaMelodia(int note[100], int durate[100]) {
int k;
for ( k = 0; note[k] != 0; k++) {}
for (int d = 0; d < k; d++) {
if (note[d] != PAUSA) {
tone(buzz, note[d], durate[d]);
}
delay(durate[d]);
}
}
bool P1Premuto, P2Premuto, P3Premuto, P4Premuto;
void Easy::controllaPulsanti() {
P3Premuto = analogRead(A4)<500;
P1Premuto = analogRead(A5)<500;
P4Premuto = !digitalRead(8);
P2Premuto = !digitalRead(12);
}