ARPEGGIATOR

Voici un arpeggiator. Il fonctionne de la façon suivante :

  • 3 boutons dont chacun crée une suite de notes. Ici le premier fait : SOL-DO-MI. Le deuxième : SOL-SI-MI. Le troisième : SOL-LA-DO.
  • 1 potentiomètre qui gère la rapidité des arpèges.

En appuyant sur les 3 boutons successivement on obtient une mélodie dont on peut régler le « tempo » en tournant le potentiomètre.

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
#include "pitches.h"
 
 
//potentiometre
int val;
int analogPin = A0;
 
//BOUTTON
const int buttonPin1 = 2;
int buttonState = 0;
 
const int buttonPin2 = 4;
int buttonState2 = 0;
 
const int buttonPin3 = 7;
int buttonState3 = 0;
 
//haut parleur
int speaker = 9;
int speaker2 = 10;
 
 
//NOTES
int nbNotes = 3;
int notes [] = {NOTE_G3, NOTE_C4, NOTE_E4};
int notes2 [] = {NOTE_G3, NOTE_B3, NOTE_E4};
//BASS
int notes3 [] = {NOTE_G3, NOTE_A3, NOTE_C4};
 
 
void setup() {
 
  Serial.begin(9600);
 
  //bouton1
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
 
  mute();
 
  //potentiometre
  pinMode ( analogPin, INPUT);
  Serial.begin(9600);
}
 
void loop() {
 
 
  //BUTTON 1
  buttonState = digitalRead(buttonPin1);
  if ( buttonState == HIGH) {
    triggered();
  }
 
  //BUTTON 2
  buttonState2 = digitalRead(buttonPin2);
  if ( buttonState2 == HIGH) {
    triggered2();
  }
 
  //BUTTON 3
  buttonState3 = digitalRead(buttonPin3);
  if ( buttonState3 == HIGH) {
    triggered3();
  }
 
 
}
 
void mute() {
  noTone(speaker);
}
 
void triggered() {
 
  //valeurs potentiometre
  val = analogRead(analogPin);
  int blink1 = map(val, 0, 1023, 0, 500);
  //////
 
  for (int i = 0; i < nbNotes; i++) {
    tone(speaker, notes[i], 200);
    delay(blink1);
     
  }
  mute();
}
 
void triggered2() {
 
  //valeurs potentiometre
  val = analogRead(analogPin);
  int blink1 = map(val, 0, 1023, 0, 500);
  //////
 
  for (int i = 0; i < nbNotes; i++) {
    tone(speaker, notes2[i], 200);
    delay(blink1);
  }
  mute();
}
 
void triggered3() {
 
  //valeurs potentiometre
  val = analogRead(analogPin);
  int blink1 = map(val, 0, 1023, 0, 500);
  //////
 
  for (int i = 0; i < nbNotes ; i++) {
    tone(speaker, notes3[i], 500);
    delay(blink1);
  }
  mute();
 
}