Go Down

Topic: need help with connecting and controlling several leds (Read 1 time) previous topic - next topic

Ruffsta

ok, i got the following: http://forum.arduino.cc/index.php?topic=66681.0

Code: [Select]

int array[12] = {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,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 } ;

void setup()
{
  Serial.begin(115200);

  // next 3 lines are for randomizing the randomgenerator.
  Serial.println("press a key");
  while (Serial.available() ==0);
  randomSeed(micros() +  Serial.read());
 
  // this is the trick
  for (int i= 0; i< 80; i++)
  {
    int pos = random(80);
    int t = array[i];   
    array[i] = array[pos];
    array[pos] = t;
  }

  for (int i= 0; i< 80; i++)
  {
    Serial.print(i);
    Serial.print(": ");
    Serial.println(array[i]);
  }
}

void loop(){}


it went to 12, i changed it to 80 for my project..

i would like to know how to connect 80 leds (bi-color) together and each turn on based on number generated.. IE, if number 12 is generated then led 12 will light up and stay lit - a delay of say 2 seconds another random number is generated - say number 4, then led 4 will light up and stay lit as well.

the only other thing that needs to be added to the code is only draw 20 numbers then stop OR delay for like 10 seconds then turn off all lit leds and start the process over..

please be clear on instructions because i have never done this before.. i don't how many chips, resistors, ect.. i need, but i do believe i have all the things needed - i gathered a bunch of stuff for past projects but have never used them.

thank you in advance,
Ruffsta

Ruffsta

basically i want to make a keno game

sorry about the size of image..


arduinodlb

#2
Nov 04, 2013, 07:52 am Last Edit: Nov 04, 2013, 07:59 am by arduinodlb Reason: 1
OK,

well for starters, this line:

Code: [Select]

int array[12] = {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,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 } ;


needs to change the array size, so it must be:

Code: [Select]

int array[80] = {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,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 } ;


The current code just sets up the initial random array. You now need to add some code in the loop() {} function to one by one, get the next number in the array,  display it, delay, rinse and repeat the number of times.

The randomization has all been done in the setup. No more randomization is necessary until a new game starts.

The loop() shoud look something like:

Code: [Select]


int currentIndex = 0;

loop() {
   int number = array[currentIndex]; // get the current random number
   currentIndex++; // ready for the next random number

   setLed(number, ON);

   delay(5000); // wait 5 seconds

   if (currentIndex >= 20) {
         delay(10000);
         setup(); // re-initialize the arrays and generate random number array
   }
}


Now, since you want to generate a random array for each game, you may want to move that code into it's own function so that you can call it from setup() as well as loop(). Normally, things in setup are only things that you want  to happen once at startup.

Hopefully that gives you some pointers on the coding.
Do not IM me. I will not respond. Ask questions in the forum.

CrossRoads

bi-color LEDs - 2 pins, or 3?
2 pins - Hi-Lo is one color, Lo-Hi is the other color, both Hi or both Lo is off.
3-pins - common anode or common cathode, with a control pin for each color.

MAX7219 can be used for 3-pin if common cathode - wire up 4 per column. Cathode will go low during multiplexing, and the high bits will turn on one color or the other (or both).

2-pins - wire them between 2 shift registers. Then shift in Hi-Lo or Lo-Hi into the 2 registers to drive the colors. If you change the Hi-Lo to Lo-Hi fast enough, I would think persistance of vision would allow 3rd color to be seen.

How'd your game turn out? Ever get it finished?
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Ruffsta

#4
Nov 04, 2013, 11:19 pm Last Edit: Nov 05, 2013, 12:27 am by Ruffsta Reason: 1
thank you arduinodlb for that.. very much appreciated. caught the 12 after posting  :smiley-red:

@crossroads, 2 pin.. white to show all the numbers and blue to show which numbers were picked.. no, i never did get to finish the other game.. was a big project for me to tackle alone.. though i still have all the parts for it if i choose to continue on with it. i have been away from arduino for awhile now - almost gave up on it, just figured an easier game project was the best path to take on as my first project.. so i'm still new to arduino.

the spacing i will be using:


so i'll need to space the leds evenly centered per square on a circuit board.. not sure if i should use a pegboard behind the above.. so wiring/connecting it all is what i like to see or focus on i never did a matrix or setup a circuit board.. but i magine it will look something like this:



correct? wish i could see how that's all connected on the back with the chip(s) and resistors.. assembling it all will be the hardest part for me.  i have no problems soldering.. just how is it all connected is the issue.

@crossroads - actually come to think of it, i don't know which to use 2 or 3 pin.. is there an advantage of using one or the other? i have used the 3 pin before while just playing around and making the colors work.. considering using the 3 pin now..

Paul__B

White and red is not a simple option for multi-colour LEDs.  You would be using "RGB" LEDs, where blue is merely the blue colour, whilst white is all three lit.

These of course have four wires, a common (which may be either anode or cathode, depending on the construction) and one for each of the three primary colours.

CrossRoads

#6
Nov 05, 2013, 05:09 pm Last Edit: Nov 05, 2013, 05:53 pm by CrossRoads Reason: 1
Blue & white - not sure that's available as a 2-pin LED.
3mm http://www.unique-leds.com/index.php?target=products&product_id=1847
5mm http://www.unique-leds.com/index.php?target=products&product_id=1848

Then again, maybe it is!
"This LED has 3 leads, one Anode (+) each for the colors, and a common Cathode(-)."

Common cathode too - cool.
So, take 4 of these, connect the cathodes together, will go to a MAX7219 Digit Pin.
Then the 8 anodes (from 4 parts) will go to the 8 Segment pins.
Wire up 4 more to the next digit pin, and the anodes in parallel with the first set.
Etc. for 6 more sets.  Now you have 32 blue/white LEDs, 64 LEDs total.
You can see that you have wired up 4 column pairs of this
http://www.futurlec.com/LED/LEDM88RGCC.shtml

Wire up 32 more sets to another MAX7218, giving 64 total.
Don't connect the 2 chips outputs together.
Drive both via SPI, give each its own chip select signal to make the programming easier.
MAX7219 requires writing to a couple of registers in void setup - # of digits, brightness, couple more.  After that, you are just writing data to 8 registers, #1 to 9, to control the 8 digits, or columns of data. Each column has 4 blue, and 4 white LEDs.
If the LEDs are connected to segments like this:

Segment a - blue
Segment b - white
Segment c - blue
Segment d - white
Segment e = blue
Segment f - white
Segment g - blue
Segment dp - white

then writing 0,1s to a register will turn on the LEDs that have 1s written to them.
Then it just  become s a programming task.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Paul__B

Aptly named website/ company then - "Unique LEDs".

And only 50 cents each in quantity.

Ruffsta

#8
Nov 05, 2013, 10:37 pm Last Edit: Nov 05, 2013, 10:43 pm by Ruffsta Reason: 1
@crossroads - yeah i have used the 3 pin bi-color before just to get the colors working on a breadboard, so i think i'll just stay with those.. i have lots of them for the other projects i wanted to accomplish but never go to lol.. oh well, maybe someday  :smiley-red:

i'll have to use 3 chips then if 2 only control 64 bi-color leds - the board is 80 numbers.

CrossRoads

Now the fun part - assembly.

Or, make a PCB for it with the 3 MAX7219s.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Ruffsta

@arduinodlb

Code: [Select]

int array[80] = {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,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75 } ;

  int currentIndex = 0;
 
void setup()
{
  Serial.begin(115200);

  // next 3 lines are for randomizing the randomgenerator.
  Serial.println("press a key");
  while (Serial.available() ==0);
  randomSeed(micros() +  Serial.read());
 
  // this is the trick
  for (int i= 0; i< 75; i++)
  {
    int pos = random(75);
    int t = array[i];   
    array[i] = array[pos];
    array[pos] = t;
  }

  for (int i= 0; i< 75; i++)
  {
    Serial.print(i);
    Serial.print(": ");
    Serial.println(array[i]);
  }
 
  currentIndex = 0;
}

void loop(){

    int number = array[currentIndex]; // get the current random number
    currentIndex++; // ready for the next random number

    setLed(number, ON);

    delay(5000); // wait 5 seconds

    if (currentIndex >= 20) {
          delay(10000);
          setup(); // re-initialize the arrays and generate random number array
    }
}


error:
'ON' was not declared in this scope
Code: [Select]

    setLed(number, ON);

not even sure what that line is supposed to do..

arduinodlb

My code was pseudo-code to give you the idea of what you need to do. It's not real code.
Do not IM me. I will not respond. Ask questions in the forum.

CrossRoads

Ah, I see - that would be a bit in one of the 24 bytes in the MAX7219s that gets flipped from white to blue (or blue to white) after numbers start being picked.

Looks like the stuff in setup is supposed to mix up the values in array[80] to start, then currentIndex just walks thru the list & turns on the lights.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

arduinodlb

#13
Nov 07, 2013, 07:47 am Last Edit: Nov 07, 2013, 08:32 am by arduinodlb Reason: 1
Exactly, thanks Crossroads.

The randomisation code should be separated out from setup() into a function that can be called from setup() and loop() so that when you want to start a new game, the randomisation can begin anew. The original array won't be re-initialised, but it doesn't matter in this case as the randomizer works by just swapping numbers anyway.
Do not IM me. I will not respond. Ask questions in the forum.

Go Up