I have build two versions of a ramdom selector with a HC-SR04 ultrasone sensor. The aim is to select people at random from a group of people passing the sensor within 60 cm. They are going to be the “Lucky winners”. The selection is random, but with a preset avarage, varying from 1:2 to 1:20. If “Bingo” the “Alarm” (light and a tune) will be activated. In that case the detectflag will be set and before a new person can become “Lucky winner”, this flag needs to be reset first. This is to prevent multiple hits on the same persone when this person remains within detection range.
Attached is the flowchart. If any one has idea, comment, etc… I allready wrote the code twice, ones for the AM 328P and ones for the AT85-20PU. But I want to start from scratch, since in the last one, if someone remained in detection range, it keep giving alarm in one continuous go. So I want to build this one from the ground up, this being the first step.