Pages: [1]   Go Down
Author Topic: Project 11 first returned random value not random. Why?  (Read 2010 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Jr. Member
**
Karma: 1
Posts: 62
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Project 11 uses a tilt switch but the tiltswitch is broken because it didn't fit properly. My hunch is the copper arms got pushed in trying to make it fit so I've had to improvise. So instead I'm using a simple button instead in the same place, and the same code.

Works fine but erm it's actually not especially random. The first value generated by random() is always the highest value of the array. Is this because the button changes what happens or is this some flaw in random()? After the first value it's random but the first is never random with this sketch. Does this happen using the proper tilt switch as well?

Can anyone explain this?
Logged

Photography nut trying to make the flux capacitor of macro pho

UK
Offline Offline
Jr. Member
**
Karma: 1
Posts: 62
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

For what it's worth, I made a modification to the sketch that makes the thing properly random. Basically, instead of generating a random value just when switchState == LOW, I added reply = random(11); on every void loop. So it's just endlessly creating random reply values ad infinitum rather than just when the conditions are met. Seems to work, it'll be interesting to see if this is due to using a simple switch once I getb the tilt switch I ordered. All kind of weird.
Logged

Photography nut trying to make the flux capacitor of macro pho

UK
Offline Offline
Jr. Member
**
Karma: 1
Posts: 62
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

fyi, I just checked this using the proper parts and it still doesn't work properly. The first value I always get when switching it on is 'no', ie the highest value in the array. Sloppy that a badly written sketch is in the starter kit.
Logged

Photography nut trying to make the flux capacitor of macro pho

Ohio, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

FWIW, I have the same problem with the tilt switch.  Not sure if the pins were pushed too far in or if they're just not long enough, but they don't like to stay engaged in the board.  They make contact with the metal in the breadboard, but it feels like it's spring loaded.  If I don't keep pressure on the sensor, the thing just pops out. 

Logged

Pages: [1]   Go Up
Jump to: