Go Down

Topic: Boolean list how do I finish for void loop (Read 219 times) previous topic - next topic

UnterD0G

I'm trying to make a Boolean list for a project using LEDs and I don't now how to finish the rest of the code, if you know of any guides that could help that would be great.

There are 16 LEDs and I am linking them to a keypad.


Code: [Select]
#include <Keypad.h>

int latchPin = 12;
int clockPin = 11;
int dataPin = 13;

const byte ROWS = 4;
const byte COLS = 4;
char Key = 0;

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};


bool LEDlist[]={false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,}// This is the bool list

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){
 
{
 
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(clockPin, OUTPUT);
}

  Serial.begin(9600);


}


 
void loop(){


  char customKey = customKeypad.getKey();
 
LEDlist[]={false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,}

if(customKeypad.isPressed('1')){
   Serial.println("1");
   LEDlist[0] = true   
  }
  if(customKeypad.isPressed('2')){
   Serial.println("2");
   LEDlist[1] = true
  }
   if(customKeypad.isPressed('3')){
   Serial.println("3");
   LEDlist[2] = true
  }
   if(customKeypad.isPressed('4')){
   Serial.println("4");
   LEDlist[3] = true
  }
   if(customKeypad.isPressed('5')){
   Serial.println("5");
   LEDlist[4] = true
  }
   if(customKeypad.isPressed('6')){
   Serial.println("6");
   LEDlist[5] = true
  }
   if(customKeypad.isPressed('7')){
   Serial.println("7");
   LEDlist[6] = true
  }
   if(customKeypad.isPressed('8')){
   Serial.println("8");
   LEDlist[7] = true
  }
   if(customKeypad.isPressed('9')){
   Serial.println("9");
   LEDlist[8] = true
  }
   if(customKeypad.isPressed('0')){
   Serial.println("0");
   LEDlist[9] = true
  }
   /*if ("A" == customKeypad.getKey()){
   Serial.println("A");                   
   LEDlist[10] = true                     
  }                                       
   if ("B" == customKeypad.getKey()){     
   Serial.println("B");                   
   LEDlist[11] = true                     
  }                                       
   if ("C" == customKeypad.getKey()){     
   Serial.println("C");                   
   LEDlist[12] = true
  }
   if ("D" == customKeypad.getKey()){
   Serial.println("D");
   LEDlist[13] = true
  }*/
   if(customKeypad.isPressed('#')){
   Serial.println("#");
   LEDlist[14] = true
  }
   if(customKeypad.isPressed('*')){
   Serial.println("*");
   LEDlist[15] = true
   }
   
   {
  char keypressed = customKeypad.getKey();
  if (keypressed != NO_KEY)
    {
     Serial.println(keypressed);
    }
   }
}

vaj4088

You have LEDlist defined globally and again local to the loop() function.  This can cause great confusion and is a REALLY BAD THING to do!


PaulS

Quote
I'm trying to make a Boolean list for a project using LEDs
Perhaps you have a different meaning for list that I do, but I can not imagine how to make a list, of any type, with LEDs.

Code: [Select]
void setup(){
 
{
 
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
}

Why are the pinMode calls in a useless set of braces?
The art of getting good answers lies in asking good questions.

david_2018

I'm trying to make a Boolean list for a project using LEDs and I don't now how to finish the rest of the code, if you know of any guides that could help that would be great.

There are 16 LEDs and I am linking them to a keypad.

The code you posted needs a bit of work before it will compile successfully, but the main problem is you haven't even stated what you are attempting to do. Your code has made an array of boolean variables to represent the LEDs, but only you know what you intend to do with that.

UnterD0G

my bad I'm making a MIDI launchpad using a 4x4 keypad and 16 LEDs and for my list I plan on making it so when I click a key on my keypad I will update the linked false in the list from false to true and the linked LEDs to turn on on true. if that makes it clearer as to what I'm trying to do. this is my first big project with Arduino so I'm trying to learn c++.

PaulS

You need an array of struct instances. Define a struct with the LED pin number and the pin state.

Each time there is a key press, find the corresponding entry in the array, and change the pin state. Then, apply the changed state to the corresponding pin.
The art of getting good answers lies in asking good questions.

UKHeliBob

You have LEDlist defined globally and again local to the loop() function.
Ignoring for the moment the fact that the declaration is wrongly written, as is the attempt in loop() to set the values of the array elements,  the LEDlist array is actually only declared once as global
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

vaj4088

UKHeliBob is correct.  I am sorry.  I let the array "initializer" fool me, but that is no excuse.


lastchancename

#8
Apr 24, 2019, 02:48 am Last Edit: Apr 24, 2019, 06:27 pm by lastchancename
It sounds like you might be better starting of with an array[] of struct{} for each position.
Then a switch()-case: block to perform the activities.

While this may sound complicated now, wait until you have to dynamically add 16 MIDI actions to the 16 buttons.

A little exploration before you press RUN will always help identify a better strategy.
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

UnterD0G

thanks for the help I'll look into the array I have a friend who was telling me the same thing about it I think I have a idea of what to do now.

Go Up