Hello Guys, new "noob" here =).
I´m doing this project for college and i need some help. The project consist on a midi controller, a.k.a the device that i made.
This device has 5 buttons and 5 leds,plus 5 potentiometers. The potentiometers are all ok, they´re doing what they should.
Here is the problem. I want every button to turn on a single led, the led is positioned on the side. I´ve used 5 digital inputs for leds and 5 for the buttons. The trick part (for me at least) is that i want that whenever a button is pressed and the respective led turned on, every other led will remain off, so every time i preesed a button just the led that correspond to that button will be lighted up. This is like a selector actually. On the other hand, i have a programmed patch in Ableton live. There are 4 different sound effects, so the point of the device is to select only one of the effects. Thie fifth button is for a bypass, asuming everyone know what a bypass is, i need one button to function as such, and whenever pressed, only one led will be turned on and the other ones will be turned off.
Hope i make myself clear. I´m from chile so my english may be not that good (it´s not good i think). I´ll post a photo of the device. The red button is for the bypass, and the led corresponding is in the corner.
I´ll post my starting point code. I have every led turning on with their respective button, but in order to turn off the led, i have to push the button again.
Thanks in advantage for every man/woman/reptilian/alien who give themselve time to help a newbie like me. Meanwhile, i´m goin to try to find the answer.
thanks Guys.
const int LED12 = 12;
const int LED11 = 11;
const int LED10 = 10;
const int LED9 = 9;
const int LED8 = 8;
const int BUTTON6 = 6;
const int BUTTON5 = 5;
const int BUTTON4 = 4;
const int BUTTON3 = 3;
const int BUTTON2 = 2;
int STATE2 = 0;
int STATE3 = 0;
int STATE4 = 0;
int STATE5 = 0;
int STATE6 = 0;
int OLD_VALUE2 = 0;
int OLD_VALUE3 = 0;
int OLD_VALUE4 = 0;
int OLD_VALUE5 = 0;
int OLD_VALUE6 = 0;
long pot0;
long pot1;
long pot2;
long pot3;
long pot4;
void setup() {
Serial.begin(9600);
Serial.println("inicio de sketch - valores del potenciometro");
digitalWrite(LED8, LOW);
digitalWrite(LED9, LOW);
digitalWrite(LED10, LOW);
digitalWrite(LED11, LOW);
digitalWrite(LED12, LOW);
pinMode(LED12, OUTPUT);
pinMode(LED11, OUTPUT);
pinMode(LED10, OUTPUT);
pinMode(LED9, OUTPUT);
pinMode(LED8, OUTPUT);
pinMode(BUTTON6, INPUT);
pinMode(BUTTON5, INPUT);
pinMode(BUTTON4, INPUT);
pinMode(BUTTON3, INPUT);
pinMode(BUTTON2, INPUT);}
void loop() {
pot0 = analogRead(A0)/8;
pot1 = analogRead(A1)/8;
pot2 = analogRead(A2)/8;
pot3 = analogRead(A3)/8;
pot4 = analogRead(A4)/8;
Serial.print("El valor es = ");
Serial.println(pot0);
Serial.println(pot1);
Serial.println(pot2);
Serial.println(pot3);
Serial.println(pot4);
delay(50);
int val2 = digitalRead(BUTTON2);
if ((val2 == HIGH) && (OLD_VALUE2 == LOW)){
STATE2 = 1-STATE2;
delay(10); }
OLD_VALUE2 = val2;
if (STATE2 == 1) {
digitalWrite(LED8, HIGH);}
else { digitalWrite(LED8, LOW);}
int val3 = digitalRead(BUTTON3);
if ((val3 == HIGH) && (OLD_VALUE3 == LOW)){
STATE3 = 1-STATE3;
delay(10); }
OLD_VALUE3 = val3;
if (STATE3 == 1) {
digitalWrite(LED9, HIGH);}
else { digitalWrite(LED9, LOW);}
int val4 = digitalRead(BUTTON4);
if ((val4 == HIGH) && (OLD_VALUE4 == LOW)){
STATE4 = 1-STATE4;
delay(10); }
OLD_VALUE4 = val4;
if (STATE4 == 1) {
digitalWrite(LED10, HIGH);}
else { digitalWrite(LED10, LOW);}
int val5 = digitalRead(BUTTON5);
if ((val5 == HIGH) && (OLD_VALUE5 == LOW)){
STATE5 = 1-STATE5;
delay(10); }
OLD_VALUE5 = val5;
if (STATE5 == 1) {
digitalWrite(LED11, HIGH);}
else { digitalWrite(LED11, LOW);}
int val6 = digitalRead(BUTTON6);
if ((val6 == HIGH) && (OLD_VALUE6 == LOW)){
STATE6 = 1-STATE6;
delay(10); }
OLD_VALUE6 = val6;
if (STATE6 == 1) {
digitalWrite(LED12, HIGH);}
else { digitalWrite(LED12, LOW);}
}