Hi
I´m new into Arduino, and I´m afraid, that my questions are basic knowledge. Just can´t figure it out ![]()
I´m using an Audrino Pro Micro, 5Volt. Sketch programmer: Audrino version 1.6.1.
Questions:
- I want to use 20 buttons. I can make it work with 10 buttons on A0, but I need 10 more.
Then I try to put in a code for A1, but no luck with that.
I also wonder, if it is possible to add an analog potentiometer to A2?
Please, can anyone give me some advice?
-
LEDs: How can I assign 20 LEDs - one for each button?
-
Is it possible to use the same Pro Micro for the above and MIDI to USB?
(I have tryed some MIDI to USB examples from the forums, but I can´t make it work, or worse - I don´t understand...)
Hope it´s giving any meaning for you, and I apologise for my bad English.
Thanks in advance!
Here is the code I´m struggling with:
DIY Guitar Rig 5 Footpedal
Analog pin A0
|
Ground--1K--|--------|--------|-------|-------|------|-------|-------|--------|-------|----
| | | | | | | | | |
btn1 btn2 btn3 btn4 btn5 btn6 btn7 btn8 btn9 btn10
| | | | | | | | | |
220 Ohm 390 Ohm 680 Ohm 2.2K 4.3K 8.2K 12K 20K 33K 47K
|--------|--------|-------|-------|------|-------|-------|--------|-------|------ +5V
Analog pin A1
|
Ground--1K--|--------|--------|-------|-------|------|-------|-------|--------|-------|----
| | | | | | | | | |
btn11 btn12 btn13 btn14 btn15 btn16 btn17 btn18 btn19 btn20
| | | | | | | | | |
220 Ohm 390 Ohm 680 Ohm 2.2K 4.3K 8.2K 12K 20K 33K 47K
|--------|--------|-------|-------|------|-------|-------|--------|-------|------ +5V
*/
int j = 1; // integer used in scanning the array designating column number
//2-dimensional array for assigning the buttons and there high and low values
int Button[21][3] = {{1, 834, 840}, // button 1 *1
{2, 734, 738}, // button 2 *2
{3, 604, 611}, // button 3 *3
{4, 314, 319}, // button 4 *4
{5, 189, 191}, // button 5 *5
{6, 107, 109}, // button 6 *6
{7, 75, 77}, // button 7 *7
{8, 45, 47}, // button 8 *8
{9, 882, 990}, // button 9 *9
{10, 17, 19}}; // button 10 *A
int analogpin = A1; // analog pin to read the buttons
int label = 0; // for reporting the button label
int counter = 0; // how many times we have seen new value
long time = 0; // the last time the output pin was sampled
int debounce_count = 50; // number of millis/samples to consider before declaring a debounced input
int current_state = 0; // the debounced input value
int ButtonVal;
int val = 0;
const int yellowled = 16;
const int greenled = 15;
const int redled = 14;
const int Bled = 10;
const int Yled = 9;
const int Gled = 8;
const int Rled = 7;
const int bled = 6;
const int yled = 5;
const int gled = 4;
const int rled = 3;
boolean b1 = false;
boolean b2 = false;
boolean b3 = false;
boolean b4 = false;
boolean b5 = false;
boolean b6 = false;
boolean b7 = false;
boolean b8 = false;
boolean b9 = false;
boolean b10 = false;
boolean b11 = false;
boolean b12 = false;
boolean b13 = false;
boolean b14 = false;
boolean b15 = false;
boolean b16 = false;
boolean b17 = false;
boolean b18 = false;
boolean b19 = false;
boolean b20 = false;
long randNumber;
void setup()
{
Serial.begin(9600);
Keyboard.begin();
randomSeed(analogRead(1));
randNumber = random(0,2);
val = analogRead(analogpin); // read the input pin
Serial.println(val); // debug value
delay(100); // a little delay to not hog serial monitor
int analogpin = A2; // analog pin to read the buttons
int Button[21][3] = {
{11, 834, 840}, // button 1 *B
{12, 734, 738}, // button 2 *C
{13, 604, 611}, // button 3 *D
{14, 314, 319}, // button 4 *E
{15, 189, 191}, // button 5 *F
{16, 107, 109}, // button 6 *G
{17, 75, 77}, // button 7 *H
{18, 45, 47}, // button 8 *I
{19, 882, 990}, // button 9 *J
{20, 17, 19}}; // button 10 *K
Keyboard.begin();
pinMode(yellowled, OUTPUT);
pinMode(greenled, OUTPUT);
pinMode(redled, OUTPUT);
pinMode(Bled, OUTPUT);
pinMode(Yled, OUTPUT);
pinMode(Gled, OUTPUT);
pinMode(Rled, OUTPUT);
pinMode(bled, OUTPUT);
pinMode(yled, OUTPUT);
pinMode(gled, OUTPUT);
pinMode(rled, OUTPUT);
randomSeed(analogRead(1));
randNumber = random(0,2);
}
}
void loop()
{
static float in = 4.712;
float out;
// If we have gone on to the next millisecond
if (millis() != time)
{
// check analog pin for the button value and save it to ButtonVal
ButtonVal = analogRead(analogpin);
if(ButtonVal == current_state && counter >0)
{
counter--;
}
if(ButtonVal != current_state)
{
counter++;
}
// If ButtonVal has shown the same value for long enough let's switch it
if (counter >= debounce_count)
{
counter = 0;
current_state = ButtonVal;
//Checks which button or button combo has been pressed
if (ButtonVal > 0)
{
ButtonCheck();
}
}
time = millis();
}
if (b1==true)
{
in = in + 0.0005;
if (in > 10.995)
in = 4.712;
out = sin(in) * 64 + 64;
analogWrite(rled,out);
}
if (b1==false)
{
out = 0;
analogWrite(rled,out);
}
if (b2==true)
{
in = in + 0.0005;
if (in > 10.995)
in = 4.712;
out = sin(in) * 264 + 264 + 132;
analogWrite(gled,out);
}
if (b2==false)
{
out = 0;
analogWrite(gled,out);
}
if (b3==true)
{
in = in + 0.0005;
if (in > 10.995)
in = 4.712;
out = sin(in) * 64 + 64;
analogWrite(yled,out);
}
if (b3==false)
{
out = 0;
analogWrite(yled,out);
}
if (b4==true)
{
in = in + 0.0005;
if (in > 10.995)
in = 4.712;
out = sin(in) * 64 + 64;
analogWrite(bled,out);
}
if (b4==false)
{
out = 0;
analogWrite(bled,out);
}
if (b5==true)
{
in = in + 0.0005;
if (in > 10.995)
in = 4.712;
out = sin(in) * 64 + 64 + 32;
analogWrite(Rled,out);
}
if (b5==false)
{
out = 0;
analogWrite(Rled,out);
}
if (b6==true)
{
in = in + 0.0005;
if (in > 10.995)
in = 4.712;
out = sin(in) * 264 + 264 + 264;
analogWrite(Gled,out);
}
if (b6==false)
{
out = 0;
analogWrite(Gled,out);
}
if (b7==true)
{
in = in + 0.0005;
if (in > 10.995)
in = 4.712;
out = sin(in) * 264 + 264 + 132;
analogWrite(Yled,out);
}
if (b7==false)
{
out = 0;
analogWrite(Yled,out);
}
if (b8==true)
{
in = in + 0.0005;
if (in > 10.995)
in = 4.712;
out = sin(in) * 64 + 64;
analogWrite(Bled,out);
}
if (b8==false)
{
out = 0;
analogWrite(Bled,out);
}
}
void ButtonCheck()
{
// loop for scanning the button array.
for(int i = 0; i <= 21; i++)
{
// checks the ButtonVal against the high and low vales in the array
if(ButtonVal >= Button[i][j] && ButtonVal <= Button[i][j+1])
{
// stores the button number to a variable
label = Button[i][0];
Action();
}
}
}
void Action()
{
if(label == 1)
{
b1=true;
b2=false;
b3=false;
b4=false;
b5=false;
b6=false;
b7=false;
b8=false;
b9=false;
b10=false;
Keyboard.print('1');
}
if(label == 2)
{
b1=false;
b2=true;
b3=false;
b4=false;
b5=false;
b6=false;
b7=false;
b8=false;
b9=false;
b10=false;
Keyboard.print('2');
}
// if(label == 2) evt. ect.
}
