-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredbutton_1.ino
More file actions
133 lines (102 loc) · 3.7 KB
/
Copy pathredbutton_1.ino
File metadata and controls
133 lines (102 loc) · 3.7 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
126
127
128
129
130
131
132
/* BIG RED BUTTON Midi Controller - f
or Teensy v3.1 Based on Teensy Midi example.
v2 _ Debounce At 80 | New Startup Sequence _|
By Olivier Jean for Perceptual Engineering
*/
#include <Bounce.h>
// the MIDI channel number to send messages
const int channel = 5;
// We're using INT PIN 2 & 3
// Create Bounce objects for each button. The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
// Default is 5ms changed to 80ms
Bounce button4 = Bounce(4, 80); // small button
Bounce button5 = Bounce(5, 150); // big red button
const int ledPin = 13; // onnboard led
const int led1 = 14; // pad 1
const int led2 = 15; // pad 2
void setup() {
// Initialize button Pins
pinMode(4, INPUT_PULLUP); // Button 1 ( toggle switch always open )
pinMode(5, INPUT_PULLUP); // Button 2 ( Big RED ONE ( always closed ) )
// Initialize LED's
pinMode(ledPin, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
// Startup blink of LED's to signal all is good
// Quick Loop on diagnostic LED
for ( int i = 1; i < 3; i++){
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
// Fancy LED chase :)
for (int i=0; i<3; i++){
for(int i=0;i<12;i++){ // increment automatically from 0 to 15
int a=i%2; // calculate LSB
int b=i/2 %2;
int c=i/4 %2;
int d=i/8 %2; //claculate MSB
digitalWrite(led1,d); //write MSB
digitalWrite(led2,c);
digitalWrite(led1,b);
digitalWrite(led2,a); // write LSB
delay(100); // wait for a second
}
digitalWrite(ledPin, HIGH);
digitalWrite(led1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(led2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(ledPin, LOW);
digitalWrite(led1, LOW); // turn the LED off by making the voltage LOW
digitalWrite(led2, LOW); // turn the LED off by making the voltage LOW
delay(500);
}
}
// MAIN PROGRAM -----
void loop() {
// Update all the buttons. There should not be any long
// delays in loop(), so this runs repetitively at a rate
// faster than the buttons could be pressed and released.
button4.update();
button5.update();
// Check each button for "falling" edge.
// Send a MIDI Note On message when each button presses
// Update the Joystick buttons only upon changes.
// falling = high (not pressed - voltage from pullup resistor)
// to low (pressed - button connects pin to ground)
if (button4.fallingEdge()) {
usbMIDI.sendNoteOff(64, 00, channel); // 63 = E4
digitalWrite(ledPin, LOW);
digitalWrite(led1, LOW);
}
if (button5.fallingEdge()) {
usbMIDI.sendNoteOn(65, 99, channel); // 65 = F4
digitalWrite(ledPin, HIGH);
digitalWrite(led2, HIGH);
}
// Check each button for "rising" edge
// Send a MIDI Note Off message when each button releases
// For many types of projects, you only care when the button
// is pressed and the release isn't needed.
// rising = low (pressed - button connects pin to ground)
// to high (not pressed - voltage from pullup resistor)
if (button4.risingEdge()) {
usbMIDI.sendNoteOn(64, 99, channel); // 63 = E4
digitalWrite(ledPin, HIGH);
digitalWrite(led1, HIGH);
}
if (button5.risingEdge()) {
usbMIDI.sendNoteOff(65, 0, channel); // 65 = F4
digitalWrite(ledPin, LOW);
digitalWrite(led2, LOW);
}
// MIDI Controllers should discard incoming MIDI messages.
// http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash
while (usbMIDI.read()) {
// ignore incoming messages
}
delay(2);
}