High Striker

Hi makers,
I'm working on the high-striker carnival game and would like help with coding the device.

The design of the project comprises of a micro switches at specified intervals on a scale to identify the location of the bearing and LEDs are used to represent the location of bearing.

Once a contestant hits the striker the metal bearing goes up the scale, as the bearing makes contact with the switches, they are used to trigger the subsequent LEDs sequentially as the switches are triggered.

After the switches are triggered, LEDs turn on and have to stay ON for about 3 seconds and sequentially switch-off in the reverse direction.

int s[7];
const int pincount = 6;
const int in[7] = {21, 20, 19, 18, 17, 16, 15};
const int out[7] = {13, 12, 11, 10, 9, 8, 7};
void setup() {
  
// defining the states of the pins

for (int pinin =0; pinin < pincount; pinin++) {pinMode(in[pinin], INPUT);}
for (int pinout =0; pinout < pincount; pinout++) {pinMode(out[pinout], OUTPUT);}
 
}

void loop() {

  s[0] = digitalRead(in[0]);
  s[1] = digitalRead(in[1]);
  s[2] = digitalRead(in[2]);
  s[3] = digitalRead(in[3]);
  s[4] = digitalRead(in[4]);
  s[5] = digitalRead(in[5]);
  s[6] = digitalRead(in[6]);

  if (s[0] == HIGH){digitalWrite(out[0], HIGH);}
  if (s[1] == HIGH){digitalWrite(out[1], HIGH);}
  if (s[2] == HIGH){digitalWrite(out[2], HIGH);}
  if (s[3] == HIGH){digitalWrite(out[3], HIGH);}
  if (s[4] == HIGH){digitalWrite(out[4], HIGH);}
  if (s[5] == HIGH){digitalWrite(out[5], HIGH);}
  if (s[6] == HIGH){digitalWrite(out[6], HIGH);}
 
delay(1000);
 digitalWrite(out[6], LOW);
 delay(1100);
 digitalWrite(out[6], LOW);
delay(1200);
 digitalWrite(out[6], LOW);
 delay(1300);
 digitalWrite(out[6], LOW);
 delay(1400);
 digitalWrite(out[6], LOW);
 delay(1500);
 digitalWrite(out[6], LOW);
 delay(1600);
 digitalWrite(out[6], LOW);

}

sketch_sep16a.ino (1.58 KB)

First, please post your code according to the forum guide, we can't open it on our phones/tablets.

Second, what is it you want help with?

Hi,

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Please in the IDE select "TOOLS" then "Auto Format", before reposting, it lines up indents to help make your code easy to read.

Thanks.. Tom.. :slight_smile:

I assume you want your LEDs to light immediately?

you have to put the delay off behind an if()

also, you REALLY need to use blink without delay, in one of it's many forms.
here is one form :

THIS IS NOT CODE - JUST IDEAS

IN LOOP()   after you detect the lights

 
if( start_timing == 0) ; // 1 =block if timing is running, or 0 = waits for next contestant
     if (switchChange==1) ;  // senses contestant hit
          start_timing = 1 ; // prevents this loop from being used again until after timing expires
          timingStarted = millis() ; // sets a "now" time



duration =  (millis() - timingStarted) ; // time since timing has started 

 if ( start timing == 1 )
    {
     if (duration >= 1000) ;  digitalWrite  (led6 = LOW) ; // after 1 second turn off led6
     if (duration >= 2000) ;  digitalWrite  (led5 = LOW) ;
     if (duration >= 3000) ;  digitalWrite  (led4 = LOW) ;
     if (duration >= 4000) ;  digitalWrite  (led3 = LOW) ;
     if (duration >= 5000) ;  digitalWrite  (led2 = LOW) ;
     if (duration >= 6000) ;  digitalWrite  (led1 = LOW) ;
     if (duration >= 7000) ;  switchChange=0; start_timing = 0 ;  // resets to watch for next contestant
     }

as a note, you can put all of the if() on one line to make your program easier to read
remember your " ; "

 if (s[0] == HIGH) {   digitalWrite(out[0], HIGH); switchChange=1;}
 if (s[1] == HIGH) {   digitalWrite(out[1], HIGH); switchChange=1;}
 if (s[2] == HIGH) {   digitalWrite(out[2], HIGH); switchChange=1;}
 if (s[3] == HIGH) {   digitalWrite(out[3], HIGH); switchChange=1;}
 if (s[4] == HIGH) {   digitalWrite(out[4], HIGH); switchChange=1;}
 if (s[5] == HIGH) {   digitalWrite(out[5], HIGH); switchChange=1;}
 if (s[6] == HIGH) {   digitalWrite(out[6], HIGH); switchChange=1;}

once you have this working, you might want to leave the highest point lit or even blinking, until the other go out.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How have you got your switches wired?

Thanks.. Tom.... :slight_smile:

I've attached the images

Hi,
Ops circuit;


Thanks.. Tom... :slight_smile:

After the switches are triggered, they'll have to stay ON for about 3 seconds and sequentially switch-off in the reverse direction.

You need to completely rethink this. The switches are input devices, triggered by the moving object. They can not be forced by the Arduino to be on for any period of time or to be switched off.

The LEDs are a completely different story.

Problem with micro switches is your going to slow down the ball a lot for each switch it has to go through. Add in fact that your ball is in short order likely to get stuck on one of the switches and that should steer you away.

Optical beam breaking would solve those problems.
Even more trickery would be for beam to shoot outward and for the reflectivity of the ball passing by be picked up by sensor also mounted facing outward. Kinda optical beam “making” using ball to complete

Beam breaking was initially the idea, as the entire setup will be placed in a highly light environment, there are chances of interference.

On a similar thought a laser beam breaking device was a part of the inception, but as children will be playing the game, it's not really suitable.

the entire setup will be placed in a highly light environment

Then you won't even need illuminators. Just detect the shadow of the ball using the ambient light.

Will try using the shadow of the ball as a trigger.
My main requirement is an algorithm to light the LEDs sequentially as the ball moves upwards and they have to stay on for some time and then turn off in the reverse order (irrespective of whether the bearing triggers the switches while going back down or not).

By the time the LEDs turn off, the Puck or bearing will already be at the bottom.

Some pseudo code

void loop
iterate from 0 to the number of switches (and LEDs)
has the nth switch been pressed (whatever that means for the switches you are using)?
if so, turn the nth LED on and record the time

is the nth LED on?
if so,
has it been on long enough (now minus then equals or exceeds some threshold)?
if so,
turn it off
end loop

If you think about it logically, you can see that turning an LED off some period of time after it is turned on has nothing to do with what caused it to be turned on, as long as you keep track of whether it is on or off, and when it was turned on (when it is turned off doesn't matter).

So, turning the LEDs off is a completely separate action from turning them on. You know whether to turn them on or off...

You CAN use lasers even though it is bright out and there are kids around, with a little care. Put the laser at the end of a short tube painted black inside. Put the receiver at the end of a short tube painted black inside. The tubes and black paint will take care of the ambient light issues.

The tubes, at right angles to the weight's travel path (assuming that kids can't stick there heads up the travel path), will keep the laser out of the kids eyes.

if you looked at the general concept of how to do the timing, in post #3

you see than any switch closure starts the timing
and that it looks at all the switches

I cannot imagine anyone will have the ability to make the weight travel upwards at a speed that would be faster than the scan time of scanning the switches.

Also, there is no problem with having multiple inputs, you could have an light sensor, a HALL effect sensor and microswitches.

but I am not sure why we are talking about switches when you are only asking about how to do the code for sensing and timing.

One approach: declare an array of bools to hold switch states, initially set at zeroes. As the ball flies upward and a switch is made check its corresponding array position – 1st switch to array[0], 2nd switch to array[1], etc. If that position is set to zero, change it to a one, thus turning on its LED.

When a switch *is made * and its array position already has a one in it the downward phase has begun. The ‘turning on’ section of code is now disabled and a new section is activated which will start at the highest array position holding a one and work your way down clearing array[n], array[n-1], etc. and thus turning off the LEDs, via a timer. When all are off cycle is reset.

It might be helpful to have a ‘home’ switch to know when the ball has returned to rest position.