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:
What can I do? I was thinking to implement a software LFSR.
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:
What can I do? I was thinking to implement a software LFSR.
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.
I use them to check whenever a user press a push button.
I defined them in this way
#define Power A0
#define Select A1
#define Up A2
#define Down A3
#define Left A4
#define Right A5
and in setup()
//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
So, use them as the random seed before you use them as digital pins.
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
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.
Thanks pylon, now it's definitely clear.