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?
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.
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.
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.