Go Down

Topic: High Striker (Read 266 times) previous topic - next topic

yashz123

Sep 16, 2018, 02:01 pm Last Edit: Sep 17, 2018, 06:00 pm by yashz123
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.

Code: [Select]

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);

}

PaulRB

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?

TomGeorge

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.. :)
Everything runs on smoke, let the smoke out, it stops running....

dave-in-nj

#3
Sep 16, 2018, 03:49 pm Last Edit: Sep 16, 2018, 04:21 pm by dave-in-nj
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 :

Code: [Select]


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 " ; "

Code: [Select]

 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;}


dave-in-nj

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

TomGeorge

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.... :)
Everything runs on smoke, let the smoke out, it stops running....

yashz123

#6
Sep 17, 2018, 11:47 am Last Edit: Sep 17, 2018, 11:53 am by yashz123
I've attached the images

TomGeorge

Hi,
Ops circuit;

Thanks..  Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

PaulS

#8
Sep 17, 2018, 03:29 pm Last Edit: Sep 17, 2018, 03:29 pm by PaulS
Quote
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.
The art of getting good answers lies in asking good questions.

Slumpert

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

yashz123

#10
Sep 17, 2018, 06:04 pm Last Edit: Sep 17, 2018, 06:05 pm by yashz123
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.

PaulRB

#11
Sep 17, 2018, 08:42 pm Last Edit: Sep 17, 2018, 08:49 pm by PaulRB
Quote
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.

yashz123

#12
Sep 18, 2018, 08:26 am Last Edit: Sep 18, 2018, 08:51 am by yashz123
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.

PaulS

Some pseudo code
Quote
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.
The art of getting good answers lies in asking good questions.

dave-in-nj

#14
Sep 18, 2018, 11:02 am Last Edit: Sep 18, 2018, 11:02 am by dave-in-nj
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.



Go Up