Hey guys. Im working on homework and I have to build something like a draw machine. I have 40 leds and I have to make 5 profiles (only 1 out of 40), (only 2 out of 40), (only 3 out of 40), (only 4 out of 40), (only 5 out of 40). I want to use some buttons to "set" profile. I will use Arduino Mega 2560. Im working on prototype and Im close but I need help. Problem with my code is I cant choose profile so I have to put in there comand "light up random LED" multiple times and problem with that is most of the time only 3 or 4 LED light up because random number generator choosed for example 4 two times. Take a look at my code and help me to add "profile mode" and eleminate repetition so every time I choose amount of LEDs to light up they will. Guys I really need help do what ever you want and then send me code. Thank you for your time and help.
____________________________________ CODE _________________________________________
int timeShowRandom = 2500; //this is how long picking will be
int timeShowDecision = 5000; //this will set up how ling "winners" light will be ON
int timeBlink = 15;
int buttonPin = 3; //Here I want to add 4 other options wich will set up how many "winners" will be choosed
int buttonPress = false;
int randomNumber;
int previousNo = 1;
int timePassed = 0;
void setup() {
// Set button pin
pinMode(buttonPin, INPUT);
// Set output pins
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT); ////Now I use only 5 LEDs but soon I will have to add up to 40
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
}
void getRandomNo() {
int rand = random(6,13); //This show pins where are LEDs its (fistLED,lastLED+1) so last LED is 12
if(rand == previousNo) {
getRandomNo();
} else {
randomNumber = rand;
previousNo = randomNumber;
}
}
void loop() {
// Check if button is pressed
if(digitalRead(buttonPin) == HIGH && buttonPress == false) {
buttonPress = true;
} if(buttonPress == true && timePassed <= timeShowRandom) {
getRandomNo(); // Get random pin number
digitalWrite(randomNumber, HIGH);
delay(timeBlink);
digitalWrite(randomNumber, LOW);
delay(timeBlink);
timePassed = timePassed + (timeBlink * 2);
} else if(buttonPress == true) {
digitalWrite(random(6,13), HIGH); // Set random pin on I used this to make more (5) LED light up but most of the
digitalWrite(random(6,13), HIGH); // Set random pin on time one or two out of five get same number in random
digitalWrite(random(6,13), HIGH); // Set random pin on number generator so only 4 of them will light up.
digitalWrite(random(6,13), HIGH); // Set random pin on
digitalWrite(random(6,13), HIGH); // Set random pin on
delay(timeShowDecision); // For x seconds
buttonPress = false; // Set button to be enabled again
timePassed = 0;
} else {
// Reset all output pins
digitalWrite(6, LOW); //Now I use only 5 LEDs but soon I will have to add up to 40
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
}
}