Go Down

Topic: [Solved] Random function without read the Analog 0 (Read 626 times) previous topic - next topic

stephanboy2030

May 09, 2012, 06:23 pm Last Edit: May 09, 2012, 07:22 pm by stephanboy2030 Reason: 1
I need to generate a random value between 1 and x, but my project already use all the analog pin so I can't use this page:

http://arduino.cc/en/Reference/random

What can I do? I was thinking to implement a software LFSR.

AWOL

Are you saying the analogue pins are in use as digital pins, and that's the reason you can't use them?
Normally, you only ever call the seed function once, so this could be done in setup.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

stephanboy2030

I use them to check whenever a user press a push button.

I defined them in this way
Code: [Select]

#define Power   A0
#define Select  A1
#define Up A2
#define Down A3   
#define Left A4
#define Right A5


and in setup()

Code: [Select]
  //Setup the Joystick buttons as inputs
    pinMode(Power, INPUT);
    pinMode(Up, INPUT);
    pinMode(Down, INPUT);
    pinMode(Left, INPUT);
    pinMode(Right, INPUT);
    pinMode(Select, INPUT);

  //Enable pullups on Joystick buttons
    digitalWrite(Power, HIGH);
    digitalWrite(Up, HIGH);
    digitalWrite(Down, HIGH);
    digitalWrite(Left, HIGH);
    digitalWrite(Right, HIGH);
    digitalWrite(Select, HIGH);


and using 6 push buttons between GND and each analog input.
My project is a MP3 player

AWOL

So, use them as the random seed before you use them as digital pins.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

stephanboy2030

I was confusing how the random function works. It just need to take a first value only one time, not every time that it is called, isn't it?

Thank you so much AWOL

pylon

The random function is a pseudo random number generator, a complex mathematical function returning randomly spread numbers over a range. Because every new number is calculated based on the previous it has to be initialized at some point (called seeding). For the seeding it's best to use some truly random value as it is the noise on a not connected analog input.

stephanboy2030


Go Up