Simple LED dice with source by a ardunewbieno

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
nosferatux
 
Posts: 5
Joined: Fri Aug 07, 2009 9:54 pm

Simple LED dice with source by a ardunewbieno

Post by nosferatux »

Just got my Arduino board, thought I would post it on here. Code could probably be better but I just started so I am still learning, it seems to work OK.

It uses pins 7 through 13 as output to light up the LED's, here is a picture of how I connected mine on a breadboard. Just press the reset button to "throw the dice". Need to make a button for it instead...
For some reason "Serial.println(randNumber);" is not displaying on serial, anyone have any idea why ? Do I have to define the baud rate on the code ?

Image

Here is the code:

Code: Select all

long randNumber;
int ledPin7 = 7;
int ledPin8 = 8;
int ledPin9 = 9;
int ledPin10 = 10;
int ledPin11 = 11;
int ledPin12 = 12;
int ledPin13 = 13;

void setup()
{

  randomSeed(analogRead(0));
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);
  pinMode(ledPin9, OUTPUT);
  pinMode(ledPin10, OUTPUT);
  pinMode(ledPin11, OUTPUT);
  pinMode(ledPin12, OUTPUT);  
  pinMode(ledPin13, OUTPUT);     
}

void loop()
{

  randNumber = random(1, 7);
  Serial.println(randNumber);
digitalWrite(ledPin7, HIGH);
delay(50);
digitalWrite(ledPin8, HIGH);
delay(50);
digitalWrite(ledPin9, HIGH);
delay(50);
digitalWrite(ledPin10, HIGH);
delay(50);
digitalWrite(ledPin11, HIGH);
delay(50);
digitalWrite(ledPin12, HIGH);
delay(50);
digitalWrite(ledPin13, HIGH);
delay(50);  
digitalWrite(ledPin7, LOW);
delay(50);  
digitalWrite(ledPin8, LOW);
delay(50);  
digitalWrite(ledPin9, LOW);
delay(50);  
digitalWrite(ledPin10, LOW);
delay(50);  
digitalWrite(ledPin11, LOW);
delay(50);  
digitalWrite(ledPin12, LOW);
delay(50);  
digitalWrite(ledPin13, LOW);
delay(50);  

if (randNumber == 1)
	{
digitalWrite(ledPin10, HIGH);				
	}

else if (randNumber == 2)
	{
digitalWrite(ledPin12, HIGH);
digitalWrite(ledPin8, HIGH);
	}

else if (randNumber == 3)
	{
digitalWrite(ledPin12, HIGH);
digitalWrite(ledPin8, HIGH);
digitalWrite(ledPin10, HIGH);
	}

else if (randNumber == 4)
	{
digitalWrite(ledPin7, HIGH);
digitalWrite(ledPin8, HIGH);
digitalWrite(ledPin12, HIGH);
digitalWrite(ledPin13, HIGH);
	}

else if (randNumber == 5)
	{
digitalWrite(ledPin7, HIGH);
digitalWrite(ledPin8, HIGH);
digitalWrite(ledPin12, HIGH);
digitalWrite(ledPin13, HIGH);
digitalWrite(ledPin10, HIGH);
	}

else if (randNumber == 6)
	{
digitalWrite(ledPin7, HIGH);
digitalWrite(ledPin9, HIGH);
digitalWrite(ledPin12, HIGH);
digitalWrite(ledPin8, HIGH);
digitalWrite(ledPin11, HIGH);
digitalWrite(ledPin13, HIGH);
	}
		
  delay(999999999);

}



adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Simple LED dice with source by a ardunewbieno

Post by adafruit »


nosferatux
 
Posts: 5
Joined: Fri Aug 07, 2009 9:54 pm

Re: Simple LED dice with source by a ardunewbieno

Post by nosferatux »

I did not go through tutorials on this site yet...

But moving :

Code: Select all

  Serial.begin(9600);
  Serial.println(randNumber);
Into void setup field fixed the problem. It now gives me terminal feedback.

Thanks for the pointer : )

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Simple LED dice with source by a ardunewbieno

Post by adafruit »

spending a few hours on the tutorials now may save you days later

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”