Our teacher want us to make a classical Casino Slot Machine with a matrix of 3x3 leds. He want us to randomize the state of 3 leds when a coin is detected by a button and release the coin if theres an horizontal line of 3 turned on leds, but we havent seen the topics to make such work. can someone help me out.. Thanks!
When posting code make sure to post it between code tags so it looks like this
What coin detector and coin handler do you plan to use? (need links to the specific data sheets).
Row detection: classing machines roll their things from top to bottom. So that'd imply LEDs scrolling from to to bottom or so. Or are yours simply blinking on and off randomly? Store the LED states in a 3x3 array for easy handling.
What is a "line"? There are three horizontal, three vertical and two diagonal lines of three in a 3x3 matrix. Do you want some or all of those? Easiest is a bunch of if statements.
I know how to turn of and on leds and i started viewing and trying randomSeed and random function, so far so good, but i have no idea on how to make the arduino know when a complete row is turned on and also ive got out of ideas on how to make the arduino to turn on the leds, i was thinking on running the random function get a pin and turn it on until i get 3 leds turned on but i dont know if that works.
The teacher only asked us to blink on and off the leds, and also told us to use a limit switch to detect the coins, so nothing fancy going on here.
With line I refer that we only need to use the 3 posible horizontal lines that the turned on leds can make
Heres all the code that Ive done
int led1;
int led2;
int led3;
void setup() {
Serial.begin(9600);
randomSeed(analogRead(A0));
}
void loop() {
led1 = random(2,20);
Serial.println('led1' + "," + 'led2' + "," + 'led3');
delay(1000);
}
DanyMont1505:
The teacher only asked us to blink on and off the leds, and also told us to use a limit switch to detect the coins, so nothing fancy going on here.
So you need a rather sensitive switch (coins are light in weight) and some guide rails or so to have the coin reach the limit switch. That shouldn't be too hard to build, but you may be surprised.
But then in your OP you said:
DanyMont1505:
release the coin if theres an horizontal line of 3 turned on leds
This is the coin handing part. To do this, you need some mechanism to release the coin (and give it back to the player?) or to not release the coin (and put it in another box for the machine to keep?). At the very least you have to make sure the button is released - which is not that hard, just let the coin run over it, a short press is more than enough for the Arduino.
Then about your code:
- whenever you feel the need of adding numbers to your variables, what you really need is an array. For a matrix, that'd be a 2D array.
- an LED can be on or off, 1 or 0. A value of 2-20 doesn't make sense.
- you don't do anything with led2 and led3.
The mechanical part which i forgot to explain is, you insert a coin, the switch detects it, then the game runs if you loose two servos will guide the coin to a storage bin, if you win it guides it to a return bin were the player can have it back.
Thanks for answering, i'll have a look to arrays and continue working with the code. As soon as i get it more advanced, i hope you guys can give it a look!
Again, Thanks.
Don't make it more advanced before you test the separate parts.
The LEDs, the button, the servos - test it all separately.
i have no idea on how to make the arduino know when a complete row is turned on
Of course, the Arduino already "knows" what LEDs are on. because it's turning them on.
You just need to use some if-statements and Boolean logic for whatever pattern/conditions make a "line".
This thread is two years old to the day.
OP either figured it out by now or has given up.