Bullet Train game

Post here to let others know of a project you're working on.

Moderators: Chuckt, Garth, bitfogav

Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Bullet Train game

Post by MrDEB » Tue Mar 28, 2017 3:42 am

this game is similar to Mexican Train but faster version. Had trouble inputing then counting the button presses in sub route ttt()
this is a rough draft that still needs cleaning up but it appears to work as desired.
Any suggestions appreciated.

Code: Select all

{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2017 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 3/18/2017                                                      *
*  Version : 1.0                                                            *
*  Notes   :  Bullet train game                                                              *
*          :                                                                *
*****************************************************************************
SET TIME BY PESSING  tIME SWITCH  {red led switch) to change tme of play
each press equals (1 PRESS = 250, 2 PRESS = 500, 3 PRESS = 750 )DELAYMS, (red led Portc.6 blinks for amount of time set)
first player that has the double domino required, presses the start button
1st green led comes ON then sequences from green portb.0 etc to red portc.5
to begin game after time is set, player presses red button C.5 this starts the countdown to red
When a player completes his/her turn he/she presses the red button and sequence starts again
Whemn a player times out the sequence automatically re-starts (countdown in a sub routine)
}
 {

DEVICE = 18f2221
CLOCK = 8
INCLUDE "INTOSC8.bas" 
INCLUDE "SetDigitalIO.bas"
 }
DEVICE = 18F2420           ' Tell the compiler what chip we are using
CLOCK = 8                  ' Tell the compiler what we will be setting the clock to (in Mhz)           
CONFIG MCLRE = OFF          
'CONFIG FOSC = intio67       ' Internal oscillator, IO on pins 6 and 7
'CONFIG  BOREN = OFF
INCLUDE "utils.bas"
INCLUDE "convert.bas"
INCLUDE "InternalOscillator.bas"




DIM PRESS AS BYTE     // end of players turn portB.5  used as an index pointer
DIM Time AS WORD
DIM index AS WORD
'DIM set AS portc.0   // CHANGES DELAYMS VARIABLE test
DIM x AS BYTE        // BYTE IN FOR NEXT LOOPS
DIM red0  AS portc.0   //led test
DIM red1 AS portc.1
DIM red2 AS portc.2
DIM red3 AS portc.3
DIM red4 AS portc.4
DIM red5 AS portc.5   //led test
DIM red6 AS portc.6
DIM red7 AS portc.7
dim value as byte
DIM swt AS portB.1   // switch  test
'DIM red2 AS portb.2
'DIM sec AS portb.4
DIM Buttonpress AS BYTE
DIM swt1 AS portb.0
DIM swt2 AS portb.4
DIM counter AS WORD
INTERRUPT MyInt()
 
END INTERRUPT


SUB Sequence()   // set all green etc to = 0
    while true
          
   

          
           TOGGLE (red0)  // turn on
           DELAYMS(Time)   // define time amount
           TOGGLE (red0) // turn off
           inc (index)   // index = 1
           if swt2 = 0 and index <=2
           then
           exit
           else
           swt2 = 1
           end if
           delayms(time)
           
           TOGGLE (red1)
           DELAYMS(Time)    // define time amount
           TOGGLE (red1)
           INC (index)
           if swt2 = 0 and index >=2
           then
           exit
           else
           swt2 = 1
           end if
           delayms(time) 
            '#2
           TOGGLE (red2)
           DELAYMS(Time)
           TOGGLE (red2)
           INC (index)
           if swt2 = 0 and index >=3
           then
           exit
           else
           swt2 = 1
           end if 
           delayms(time)
               '#3
           TOGGLE (red3)
           DELAYMS(Time)
           TOGGLE (red3)
           INC (index)
           if swt2 = 0 and index >=5
           then
           exit
           else
           swt2 = 1
           end if  
           delayms(time)
             '#4
           TOGGLE (red4)
           DELAYMS(Time)
           TOGGLE (red4)
           INC (index)
           if swt2 = 0 and index >=6
           then
           exit
           else
           swt2 = 1
           end if 
           delayms(time)
              '#5
           TOGGLE (red5)
           DELAYMS(Time)
           TOGGLE (red5)
           INC (index)
           if swt2 = 0 and index >=7
           then
           exit
           else
           swt2 = 1
           end if 
           delayms(time)  
               '#6
           TOGGLE (red6)
           DELAYMS(Time)
           TOGGLE (red6)
           INC (index) 
           if swt2 = 0 and index >=8
           then
           exit
           else
           swt2 = 1
           end if
           delayms(time)
           
              '#7
           TOGGLE (red7)
           DELAYMS(Time)
           TOGGLE (red7)
            INC (index)
          
         
             {    '#8
           TOGGLE (Yellow0)
           DELAYMS(Time)
           TOGGLE (Yellow0)
           
              '#9
           TOGGLE (Yellow3)
           DELAYMS(Time)
           TOGGLE (Yellow3)
          
               '#10
           TOGGLE (Red)
           DELAYMS(Time)
           TOGGLE (Red)
              }
          index = 0
         wend
         END SUB 


SUB one_blink()       ' NEED TO ADD IN DELAYMS(TIME)
          IF PRESS = 0
          THEN
     PRESS = PRESS + 1
     red0 = 1
     DELAYMS(1000)
     red0=0
     DELAYMS(1000)
     swt1 = 1
     time = 250     ' player allotment time
     ENDIF
END SUB

SUB two_blink()
          IF PRESS = 1  
          THEN
          
     PRESS = PRESS +1
     END IF
     
     IF PRESS = 2 THEN
     red0 = 1
     DELAYMS(1000)
     red0 = 0
     DELAYMS(1000)
     red0 = 1
     DELAYMS(1000)
     red0 = 0
     swt = 1
     time = 500    ' player allotment time
     ENDIF
END SUB      

SUB three_blink() 
         IF PRESS = 2  THEN
     PRESS = 3
     END IF
     
     IF PRESS = 3 THEN
     red0 = 1
     DELAYMS(1000)
     red0 = 0
     DELAYMS(1000)
     red0 = 1
     DELAYMS(1000)
     red0 = 0
     DELAYMS(1000)
     red0 = 1
     DELAYMS(1000)
     red0 = 0
     swt1 = 1
     time = 750     ' player allotment time
     ENDIF
END SUB              
         
 //  SET THE TIMER AS PER # OF BLINKS OF PORTC.5
         
SUB ttt()           
  IF swt1 = 0 AND PRESS = 0
      THEN
      DELAYMS(400)
      one_blink()
    ' press = 1
    END IF
     'if swt2 = 0 then sequence()
    'end if     
  
     IF swt1 = 0 AND PRESS = 1
     THEN
     DELAYMS(400)
     two_blink()
    ' press = 2
     END IF
     
      IF swt1 = 0 AND PRESS = 2
     THEN
     DELAYMS(400)
     three_blink()
    ' press = 3
     END IF
     
     IF PRESS >= 3 THEN PRESS = 0
     END IF
  END SUB 
    
      
     OUTPUT (red0)
     OUTPUT (red1)
     OUTPUT (red2)
     OUTPUT (red3)
     OUTPUT (red4)
     OUTPUT (red5)
     OUTPUT (red6)
     OUTPUT (red7)
    
    trisb =%00000000
    trisc =%00000000 
    trisA =%00000000
   PRESS = 0
   Buttonpress =1
   swt1 = 1
   swt2 = 1 
   red0 =0
   red1 =0
   red2 =0 
   red3 =0
   red4 =0
   red5 =0
   red6 =0 
   red7 =0
   Time = 1000
   index = 0   
   WHILE true
   REPEAT
   ttt()         ' input player time alotment
  ' index = 1
   UNTIL swt2 = 0   ' select # of blinks (1-3) for time allotment
   ENABLE(MyInt)    ' interrupt jump if swt2 is pressed
   Sequence()
   'while true  ' 10 leds blink to indicate count down of players time selected
    {
     for x = 0 to 5        testing and confirm code is returning
     if index < 7 then
     red0 = 1
     delayms(500)
     toggle (red0)
     delayms(400)
     end if 
     next
    }
 WEND
end if
   

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bullet Train game

Post by brad » Fri Mar 31, 2017 5:14 pm

Do you have a photo or video of your project?

tumbleweed
newbie
newbie
Posts: 5
Joined: Tue Mar 29, 2016 12:47 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bullet Train game

Post by tumbleweed » Sat Apr 01, 2017 11:16 pm

I'm not sure why I do this, but from looking at that code this is what I see...

Code: Select all

DIM red0 AS portc.0
DIM swt1 AS portb.0
DIM swt2 AS portb.4

// make ALL pins OUTPUTS, so can't read any switches !!!!!
TRISB = %00000000
TRISC = %00000000
TRISA = %00000000

// This sets the "switch inputs", which are really outputs because of the above.
// (NB - why you set a "switch input" is beyond me, but so be it)
// HOWEVER, since the PORTB pins default to analog mode THEY WILL ALWAYS READ 0
// NO MATTER WHAT even though they are outputs. That means ALL of tests for swt1
// and swt2 are completely bogus... they will ALWAYS = 0 !!!!
swt1 = 1
swt2 = 1

// so all of the code results in...
while true
    DELAYMS(400)
    ' one blink
    red0 = 1
    DELAYMS(1000)
    red0 = 0
    DELAYMS(1000)

    DELAYMS(400)
    ' two blink
    red0 = 1
    DELAYMS(1000)
    red0 = 0
    DELAYMS(1000)
    red0 = 1
    DELAYMS(1000)
    red0 = 0
    DELAYMS(1000)

    DELAYMS(400)
    ' three blink
    red0 = 1
    DELAYMS(1000)
    red0 = 0
    DELAYMS(1000)
    red0 = 1
    DELAYMS(1000)
    red0 = 0
    DELAYMS(1000)
    red0 = 1
    DELAYMS(1000)
    red0 = 0
    DELAYMS(1000)
wend
If by working you mean the bullet train derails and all the passengers die then it should work like a champ.
Even ignoring the not-so-obvious mistake the code is indeed a train wreck.

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bullet Train game

Post by MrDEB » Tue Apr 04, 2017 3:07 pm

I see what your saying but as the code I posted it works.
I think, not sure, but I questioned the same and tried trisc-%11111111
no difference I recall but will run the code again to be sure. Waiting for a new picki2 from China as mine decide to fry itself.
Have a pickit3 but the board needs its own power which I haven't addressed yet.

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Bullet Train game

Post by brad » Wed Apr 05, 2017 8:34 pm

While I have to admit that i've not been particularly helpful lately due to time constraints @tumbleweed it seems that your post was made in order to put MrDEB down. If I've got that wrong then I apologise however regardless of someones coding ability - let's show some respect, after all the very reason he posted was to get some help.

Could you perhaps provide a schematic of your circuit MrDEB so I/we can get a more complete picture of your project?

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 5 guests