Ok, so this is the first program I have written in arduino (I used an arduino uno). It is supposed to be a slot machine thing that has the led's (the led's are used as the sets of slots) hooked up to pins 2-4, pins 6-8, and pins 10-12. I know you guys might not want to take the time to copy the program and hook it up to your arduinos but I was just wondering if I could get some tips. I know it is not written well and I was just wondering if I could get some general tips on better programming skills. Here is the code:
int wincheck=0;
int count=0;
int rundelaymax;
int leftstop;
int midstop;
int rdmone = 0;
int rundelay = 50;
int leftleds = 5;
int midleds = 9;
int countnum = 0;
void setup() {
//set each pins used for the slot machine as outputs (pins 2-4, pins 6-8, pins 10-12)
for(int pinsout = 2;pinsout<5;pinsout++){
pinMode(pinsout, OUTPUT);
pinMode(pinsout+4, OUTPUT);
pinMode(pinsout+8, OUTPUT);
}
randomSeed(analogRead(0));
}
// here is the meat and potatoes of the program
void loop() {
//assign random numbers to each set of led's to make them stop (only assign them the first time the program gets run)
rdmone +=1;
if(rdmone==1){
leftstop = random(17,20);
midstop = random(20,23);
rundelaymax = random(600,700);
}
//start system that has led's running up like a slot machine
for(int rightleds=2;rightleds<5;rightleds+=1){
leftleds+=1;
midleds+=1;
rundelay+=20;
countnum+=1;
//right set of led's (pins 2-4) turn on (during the running of the slot machine)
digitalWrite(rightleds, HIGH);
//left set of led's (pins 6-8) turn on (during the running of the slot machine)
if(countnum>leftstop){}
else
digitalWrite(leftleds, HIGH);
//middle set of led's (pins 10-12) turn on (during the running of the slot machine)
if(countnum>midstop){}
else
digitalWrite(midleds, HIGH);
delay(rundelay); // delay before moving up to next LED
//right set of led's (pins 2-4) turn off (during the running of the slot machine)
digitalWrite(rightleds, LOW);
//left set of led's (pins 6-8) turn off (during the running of the slot machine)
if(countnum>(leftstop-1)){}
else
digitalWrite(leftleds, LOW);
//middle set of led's (pins 10-12) turn off (during the running of the slot machine)
if(countnum>(midstop-1)){}
else
digitalWrite(midleds, LOW);
//stop running of slots when all slots have stopped running
if(rundelay>rundelaymax){
while(1){
digitalWrite(rightleds, HIGH);
//check if you are a winner
for(wincheck=2;wincheck<5;wincheck+=1){
if(digitalRead(wincheck)==1&&digitalRead(wincheck+4)==1&&digitalRead(wincheck+8)==1){
// blink all led's on an off with a delay of 1 second in between each blink
delay(600);
for(count=0;count<3;count+=1){
for(wincheck=2;wincheck<5;wincheck+=1){
digitalWrite(wincheck,HIGH);
digitalWrite((wincheck+4),HIGH);
digitalWrite((wincheck+8),HIGH);
}
delay(1000);
for(wincheck=2;wincheck<5;wincheck+=1){
digitalWrite(wincheck,LOW);
digitalWrite((wincheck+4),LOW);
digitalWrite((wincheck+8),LOW);
}
delay(1000);
}
while(1){}
}
}
//blink an x in the led's with a delay of .5 seconds in between each blink to indicate that you lost
for(count=0;count<3;count+=1){
delay(500);
digitalWrite(2,HIGH);
digitalWrite(4,HIGH);
digitalWrite(7,HIGH);
digitalWrite(10,HIGH);
digitalWrite(12,HIGH);
digitalWrite(3,LOW);
digitalWrite(6,LOW);
digitalWrite(8,LOW);
digitalWrite(11,LOW);
delay(500);
digitalWrite(2,LOW);
digitalWrite(4,LOW);
digitalWrite(7,LOW);
digitalWrite(10,LOW);
digitalWrite(12,LOW);
}
while(1){}
}
}
}
if(leftleds>7){
leftleds=5;}
if(midleds>11){
midleds=9;}
}