;DekAnimator.gcb
;This code will move glow on 4 Dekatron tubes using 5 different patterns
;Uses On Interrupt method

;*************************************************************

;----- Settings
#chip   16F628A, 4        ;PIC16F628A running at 4 MHz
#config MCLRE=ON          ;reset handled externally
#config osc=int           ;use internal clock
#option explicit          ;requires all variables to be dimensioned.
                          ;(If not, see compiling error)

;----- Constants (#defines)
#define TubeAG1 PORTA.0   ;output to turn on G1 on Tube A (PIC pin 17)
#define TubeAG2 PORTA.1   ;output to turn on G2 on Tube A (PIC pin 18)
#define TubeBG1 PORTA.2   ;output to turn on G1 on Tube B (PIC pin 1)
#define TubeBG2 PORTA.3   ;output to turn on G2 on Tube B (PIC pin 2)
#define TubeCG1 PORTB.2   ;output to turn on G1 on Tube C (PIC pin 8)
#define TubeCG2 PORTB.1   ;output to turn on G2 on Tube C (PIC pin 7)
#define TubeDG1 PORTB.5   ;output to turn on G1 on Tube D (PIC pin 11)
#define TubeDG2 PORTB.6   ;output to turn on G2 on Tube D (PIC pin 12)
#define Switch1 PORTA.4   ;input from Anim1 switch (PIC pin 3)
#define Switch2 PORTA.6   ;input from Anim2 switch (PIC pin 15)
#define Switch3 PORTA.7   ;input from Anim3 switch (PIC pin 16)
#define Switch4 PORTB.4   ;input from Anim4 switch (PIC pin 10)
#define Switch5 PORTB.7   ;input from Anim5 switch (PIC pin 13)
#define IntPin  PORTB.0   ;input for interrupt (PIC pin 6)
#define DekRST  PORTB.3   ;output-Dekatron reset (PIC pin 9)
#define PICrst  PORTA.5   ;input-PIC reset (PIC pin 4)

;----- Variables - must be dimensioned

dim spin as Byte          ;number of times to repeat a group of moves
dim delay as Byte         ;Inter-pin delay for some animations
dim busybit as bit        ;to keep PIC busy
dim counter as Byte       ;for Animation loops
dim howmany as Byte       ;for Animation loops
dim visTime as Byte       ;for Animation, time pins are visible

;----- I/O (dir)
dir PORTA 0b11110000      ;(RA0,1,2,3 for Guides, RA4,6,7 for switches, RA5 for PIC reset)
dir PORTB 0b10010001      ;(RB1,2,5,6 for Guides, RB0 for interrupt, RB4,7 for switches, RB3 for DEK reset)

;----- Program
PortA = 0 : PortB = 0        ;sets all guides high before reset.

                             ;Initial Dekatron reset:
   wait 1 s                  ;Allows time for settling AND caps to build voltage
   Set DekRST on             ;Reset all tubes (Forces glow to K0 on all tubes)
   wait 5 ms
   Set DekRST off
                             ;IF TUBES DON'T START AT KO, INCREASE VOLTAGE POT- RESET CANNOT WORK IF
                             ;440v NOT PRESENT ON ALL 4 TUBES AT START UP.

;----- Interrupt Setup
On Interrupt ExtInt0 Call Switches   ;Set up On Interrupt method to INTE (ExtInt0 is the EVENT in GCB);
                                     ;automatically enables INTE on PORTB.0 (bit in INTCON register of 16F628A)
  INTEDG = 0                         ;set INTE to falling edge (bit in OPTION register of 16F628A )

Start:                       ;keeps PIC occupied until a key pressed
   busybit =1                ;initial value
 Do
   busybit = NOT busybit
 Loop

;***********************************************************************************************************
Animation1:
PortA = 0 : PortB = 0        ;sets all guides high before reset.

   wait 1 s                  ;Dekatron reset
   Set DekRST on             ;Frame 1. Reset all tubes, all at K0
   wait 5 ms
   Set DekRST off

   IntOn                     ;Re-enable Global interrupt

   Repeat 2                  ;Frame 2. Visible move A K0 to A 2.2
    AVCG1
    AVG12
    AVG2C
   End Repeat
    AVCG1
    AVG12
   Repeat 2                  ;Frame 3. Quickmove B K0 to B 7.1
    BCG2
    BG21
    BG1C
   End Repeat
    BCG2
    BG21
   Repeat 7                  ;Frame 4. Visible move B 7.1 to B K5
    BVG12
    BVG2C
    BVCG1
   End Repeat
    BVG12
    BVG2C

   visTime = 30
   howmany = 1

 Do

  For counter = 1 to 5
  visTime = visTime - 5

mark:

   howmany = howmany + 1
   If howmany = 20 then goto Animation1

   Repeat 7                   ;Frame 5. Visible move D K0 to D 7.2
    DCG1  : wait visTime ms
    DG12  : wait visTime ms
    DG2C  : wait visTime ms
   End Repeat
    DCG1  : wait visTime ms
    DG12  : wait visTime ms
   Repeat 2                   ;Frame 6. Quickmove C K0 to C 2.1
    CCG1
    CG12
    CG2C
   End Repeat
    CCG1
   Repeat 7                   ;Frame 7. Visible move C 2.1 to C K0
    CG12  : wait visTime ms
    CG2C  : wait visTime ms
    CCG1  : wait visTime ms
   End Repeat
    CG12  : wait visTime ms
    CG2C  : wait visTime ms
   Repeat 2                   ;Frame 8. Quickmove A 2.2 to A K5
    AG2C
    ACG1
    AG12
   End Repeat
    AG2C
   Repeat 7                   ;Frame 9. Visible move A K5 to A 2.2
    ACG1  : wait visTime ms
    AG12  : wait visTime ms
    AG2C  : wait visTime ms
   End Repeat
    ACG1  : wait visTime ms
    AG12  : wait visTime ms
   Repeat 2                   ;Frame 10. Quickmove B K5 to B 7.1
    BCG1
    BG12
    BG2C
   End Repeat
    BCG1
   Repeat 7                   ;Frame 11. Visible move B 7.1 to B K5
    BG12  : wait visTime ms
    BG2C  : wait visTime ms
    BCG1  : wait visTime ms
   End Repeat
    BG12  : wait visTime ms
    BG2C  : wait visTime ms
   Repeat 2                   ;Frame 12 Quickmove D 7.2 to D K0
    DG2C
    DCG1
    DG12
   End Repeat
    DG2C

   Next counter
   If visTime = 5 then goto mark
  Loop

;***********************************************************************************************************
Animation2:
   PortA = 0 : PortB = 0        ;sets all guides high before reset.

   wait 1 s                  ;Dekatron reset
   Set DekRST on             ;Frame 1. Reset all tubes, all at K0
   wait 5 ms
   Set DekRST off

   IntOn                     ;Re-enable Global interrupt

 Do
  For spin = 1 to 5          ;Frame 2.  All tubes clockwise
   Repeat 10
    AVCG1
    BVCG1
    CVCG1
    DVCG1

    AVG12
    BVG12
    CVG12
    DVG12

    AVG2C
    BVG2C
    CVG2C
    DVG2C
   End Repeat
  Next spin

  For spin = 1 to 5          ;Frame 3.  All tubes counterclockwise
   Repeat 10
    AVCG2
    BVCG2
    CVCG2
    DVCG2

    AVG21
    BVG21
    CVG21
    DVG21

    AVG1C
    BVG1C
    CVG1C
    DVG1C
   End Repeat
  Next spin

  For spin = 1 to 5          ;Frame 4.  A & D clockwise, B & C counterclockwise
   Repeat 10
    AVCG1
    BVCG2
    CVCG2
    DVCG1

    AVG12
    BVG21
    CVG21
    DVG12

    AVG2C
    BVG1C
    CVG1C
    DVG2C
   End Repeat
  Next spin

  For spin = 1 to 5          ;Frame 5.  A & D counterclockwise, B & C clockwise
   Repeat 10
    AVCG2
    BVCG1
    CVCG1
    DVCG2

    AVG21
    BVG12
    CVG12
    DVG21

    AVG1C
    BVG2C
    CVG2C
    DVG1C
   End Repeat
  Next spin
 Loop

;***********************************************************************************************************
Animation3:
   PortA = 0 : PortB = 0     ;sets all guides high before reset.

   wait 1 s
   Set DekRST on             ;FRAME 1. Reset all tubes, all at K0
   wait 5 ms
   Set DekRST off

   IntOn                     ;Re-enable Global interrupt

 visTime = 160

 Do
 For counter = 1 to 5
 visTime = vistime / 2
   Repeat 5                  ;FRAME 2. Quickmoves A K0 to A K5, B K0 to B K5,
     ACG1                    ;                    C K0 to C K5, D K0 to D K5,
     AG12
     AG2C
   End Repeat

   Repeat 5
     BCG1
     BG12
     BG2C
     wait 80 us
   End Repeat

   Repeat 5
     CCG1
     CG12
     CG2C
   End Repeat

   Repeat 5
     DCG1
     DG12
     DG2C
   End Repeat

  For spin = 1 to 5
   Repeat 5                  ;Frame 3. Multiplex Visible moves C K5 to C K0, D K5 to D K0,
     CCG2
     DCG1
     CG21
     DG12
     CG1C
     DG2C
     wait visTime ms
   End Repeat

   Repeat 5                  ;and back
     DCG2
     CCG1
     DG21
     CG12
     DG1C
     CG2C
     wait visTIme ms
   End Repeat
   Next spin

     Repeat 5
     CCG2
     DCG1
     CG21
     DG12
     CG1C
     DG2C
     wait visTime ms
   End Repeat                ;back to K0

  For spin = 1 to 5
   Repeat 10                 ;Frame 4. Multiplex A K5 to C K5 and B K5 to B K5
     ACG1
     BCG2
     AG12
     BG21
     AG2C
     BG1C
     wait visTime ms
   End Repeat
  Next spin

  For spin = 1 to 5
   Repeat 5                  ;Frame 5. Multiplex C K0 to C K5 and D K0 to D K5
     CCG2
     DCG1
     CG21
     DG12
     CG1C
     DG2C
     wait visTime ms
   End Repeat

   Repeat 5                  ;and back
     DCG2
     CCG1
     DG21
     CG12
     DG1C
     CG2C
     wait visTime ms
   End Repeat
  Next spin

   Repeat 5                  ;Frame 6. Multiplex C K0 to C K5 and D K0 to D K5
     CCG1
     DCG2
     CG12
     DG21
     CG2C
     DG1C
     wait visTime ms
   End Repeat
   If visTime = 5 then visTime = 160
   Next counter
 Loop

;***********************************************************************************************************
Animation4:
   PortA = 0 : PortB = 0      ;sets all guides high before reset.

   wait 1 s
   Set DekRST on              ;Frame 1. Reset all tubes, all at K0
   wait 5 ms
   Set DekRST off

   IntOn                      ;Re-enable Global interrupt

 Do
  For spin = 1 to 3
    Repeat 5                  ;Frame 2. Visible move A K0 to A K5
      AVCG2
      AVG21
      AVG1C
    End Repeat

    Repeat 5                  ;Frame 3. Visible move C K0 to C K5
      CVCG2
      CVG21
      CVG1C
    End Repeat

    Repeat 5                  ;Frame 4. Visible move C K5 to C K0
      CVCG1
      CVG12
      CVG2C
    End Repeat

    Repeat 5                  ;Frame 5. Visible move A K5 to A K0
      AVCG1
      AVG12
      AVG2C
    End Repeat
  Next spin

    Repeat 2
      AVCG1                   ;Frame 6. Visible move A K0 to A 2.1
      AVG12
      AVG2C
    End Repeat
      AVCG1

    Repeat 2                  ;Frame 7. Quickmove B K0 to B 7.2
      BCG2
      BG21
      BG1C
    End Repeat
      BCG2

  For spin = 1 to 3
    Repeat 4                  ;Frame 8. Visible move B 7.2 to B 2.1
      BVG2C
      BVCG1
      BVG12
    End Repeat
      BVG2C
      BVCG1

    Repeat 4                  ;Frame 9. Visible move B 2.1 to B 7.2
      BVG1C
      BVCG2
      BVG21
    End Repeat
      BVG1C
      BVCG2

      Repeat 4                ;Frame 10. Visible move A 2.1 to A 7.2
      AVG1C
      AVCG2
      AVG21
    End Repeat
      AVG1C
      AVCG2

    Repeat 4                  ;Frame 11. Visible move A 7.2 to A 2.1
      AVG2C
      AVCG1
      AVG12
    End Repeat
      AVG2C
      AVCG1
  Next spin

  For spin = 1 to 3
    Repeat 9                  ;Frame 12. Visible move B 7.2 to B K8
      BVG21
      BVG1C
      BVCG2
    End Repeat
      BVG21
      BVG1C
      BVCG2
  Next spin

    Repeat 3                  ;Frame 13. Visible move B K8 to B K5
      BVCG2
      BVG21
      BVG1C
    End Repeat

    Repeat 7                  ;Frame 14. Visible move D K0 to D 7.1
      DVCG1
      DVG12
      DVG2C
    End Repeat
      DVCG1

    Repeat 2                  ;Frame 15. Quickmove C K0 to C 2.1
      CCG1
      CG12
      CG2C
    End Repeat
      CCG1

    Repeat 2                  ;Frame 16. Visible move C 2.1 to C K0
      CVG1C
      CVCG2
      CVG21
    End Repeat
      CVG1C

    Repeat 10                  ;Frame 17. Visible move C K0 to C K0
      CVCG2
      CVG21
      CVG1C
    End Repeat

    Repeat 2                  ;Frame 18. Quickmove A 2.1 to A K5
      AG12
      AG2C
      ACG1
    End Repeat
      AG12
      AG2C

    Repeat 5                  ;Frame 19. Visible move A K5 to A K0
      AVCG1
      AVG12
      AVG2C
    End Repeat

    Repeat 5                  ;Frame 20A. Quickmove B K5 to B K0
      BCG1
      BG12
      BG2C
    End Repeat

    Repeat 2                  ;Frame 20B. Quickmove D 7.1 to D K0
      DG12
      DG2C
      DCG1
    End Repeat
      DG12
      DG2C
 Loop

;***********************************************************************************************************
Animation5:                   ;For this anim, the 30 pins on each tube were assigned #s 1-30 with K0 = 1,
                              ;going clockwise.  Then, which pin would be visible on each tube was assigned
                              ;randomly.
   PortA = 0 : PortB = 0      ;sets all guides high before reset.

   wait 1 s
   Set DekRST on              ;Frame 1. Reset all tubes, all at K0
   wait 5 ms
   Set DekRST off

   IntOn                      ;Re-enable Global interrupt

   howmany = 1
   visTime = 128
Do
  For counter = 1 to howmany
   Repeat 4                       ;Frame 2. Quickmoves to A17, B29, C15, D19
     ACG2
     AG21
     AG1C
   End Repeat
     ACG2
     AG21
     wait visTime ms               ;to make pin visible
     BCG2
     BG21
     wait visTime ms
   Repeat 4
     CCG1
     CG12
     CG2C
   End Repeat
     CCG1
     CG12
     wait visTime ms
   Repeat 4
     DCG2
     DG21
     DG1C
   End Repeat
     wait visTime ms

   Repeat 3                   ;Frame 3. Quickmoves to A8, B14, C9, D2
     AG1C
     ACG2
     AG21
   End Repeat
     wait visTime ms
   Repeat 5
     BG12
     BG2C
     BCG1
   End Repeat
     wait visTime ms
   Repeat 2
     CG21
     CG1C
     CCG2
   End Repeat
     wait visTime ms
   Repeat 4
     DCG1
     DG12
     DG2C
   End Repeat
     DCG1
     wait visTime ms

     AG12                     ;Frame 4. Quickmoves to A10, B6, C20, D14
     AG2C
     wait visTime ms
   Repeat 2
     BG1C
     BCG2
     BG21
   End Repeat
     BG1C
     BCG2
     wait visTime ms
   Repeat 3
     CG2C
     CCG1
     CG12
   End Repeat
     CG2C
     CCG1
     wait visTime ms
   Repeat 4
     DG12
     DG2C
     DCG1
   End Repeat
     wait visTime ms

   Repeat 4                   ;Frame 5. Quickmoves to A27, B20, C4, D16
     ACG2
     AG21
     AG1C
   End Repeat
     ACG2
     wait visTime ms
   Repeat 4
     BG2C
     BCG1
     BG12
   End Repeat
     BG2C
     BCG1
     wait visTime ms
   Repeat 4
     CG12
     CG2C
     CCG1
   End Repeat
     CG12
     CG2C
     wait visTime ms
     DG12
     DG2C
     wait visTime ms

   Repeat 4                   ;Frame 6. Quickmoves to A14, B18, C22, D30
     AG21
     AG1C
     ACG2
   End Repeat
     AG21
     wait visTime ms
     BG1C
     BCG2
     wait visTime ms
   Repeat 4
     CCG2
     CG21
     CG1C
   End Repeat
     wait visTime ms
   Repeat 4
     DCG1
     DG12
     DG2C
   End Repeat
     DCG1
     DG12
     wait visTime ms

   Repeat 2                    ;Frame 7. Quickmoves to A22, B9, C2, D9
     AG12
     AG2C
     ACG1
   End Repeat
     AG12
     AG2C
     wait visTime ms
   Repeat 3
     BG21
     BG1C
     BCG2
   End Repeat
     wait visTime ms
   Repeat 3
     CCG1
     CG12
     CG2C
   End Repeat
     CCG1
     wait visTime ms
   Repeat 3
     DG2C
     DCG1
     DG12
   End Repeat
     wait visTime ms

   Repeat 2                   ;Frame 8. Quickmoves to A1, B22, C27, D17
     ACG1
     AG12
     AG2C
   End Repeat
     ACG1
     AG12
     wait visTime ms
   Repeat 4
     BG2C
     BCG1
     BG12
   End Repeat
     BG2C
     wait visTime ms
     CG1C
     CCG2
     CG21
     CG1C
     CCG2
     wait visTime ms
   Repeat 2
     DG2C
     DCG1
     DG12
   End Repeat
     DG2C
     DCG1
     wait visTime ms

   Repeat 3                 ;Frame 9. Quickmoves to A21, B2, C21, D26
     ACG2
     AG21
     AG1C
   End Repeat
     ACG2
     wait visTime ms
   Repeat 3
     BCG1
     BG12
     BG2C
   End Repeat
     BCG1
     wait visTime ms
   Repeat 2
     CG21
     CG1C
     CCG2
   End Repeat
     wait visTime ms
   Repeat 3
     DG12
     DG2C
     DCG1
   End Repeat
     wait visTime ms

   Repeat 2                 ;Frame 10. Quickmoves to A29, B26, C14, D20
     AG2C
     ACG1
     AG12
   End Repeat
     AG2C
     ACG1
     wait visTime ms
   Repeat 2
     BG1C
     BCG2
     BG21
   End Repeat
     wait visTime ms
   Repeat 2
     CG21
     CG1C
     CCG2
   End Repeat
     CG21
     wait visTime ms
   Repeat 2
     DG1C
     DCG2
     DG2C
   End Repeat
     wait visTime ms

   Repeat 4                  ;Frame 11. Quickmoves to A12, B28, C11, D15
     AG12
     AG2C
     ACG1
   End Repeat
     AG12
     wait visTime ms
     BG12
     BG2C
     wait visTime ms
     CG1C
     CCG2
     CG21
     wait visTime ms
     DG1C
     DCG2
     DG21
     DG1C
     DCG2
     wait visTime ms

   Repeat 2                   ;Frame 12. Quickmoves to A6, B5, C25, D27
     AG21
     AG1C
     ACG2
   End Repeat
     wait visTime ms
   Repeat 2
     BCG1
     BG12
     BG2C
   End Repeat
     BCG1
     wait visTime ms
   Repeat 4
     CG12
     CG2C
     CCG1
   End Repeat
     CG12
     CG2C
     wait visTime ms
   Repeat 4
     DG2C
     DCG1
     DG12
   End Repeat
     wait visTime ms

   Repeat 2                   ;Frame 13. Quickmoves to A30, B8, C28, D6
     AG21
     AG1C
     ACG2
   End Repeat
     wait visTime ms
     BG12
     BG2C
     BCG1
     wait visTime ms
     CCG1
     CG12
     CG2C
     wait visTime ms
   Repeat 3
     DG2C
     DCG1
     DG12
   End Repeat
     wait visTime ms

   Repeat 4                   ;Frame 14. Quickmoves to A18, B24, C16, D23
     AG21
     AG1C
     ACG2
   End Repeat
     wait visTime ms
   Repeat 4
     BG1C
     BCG2
     BG21
   End Repeat
     BG1C
     BCG2
     wait visTime ms
   Repeat 4
     CCG2
     CG21
     CG1C
   End Repeat
     wait visTime ms
   Repeat 4
     DG21
     DG1C
     DCG2
   End Repeat
     DG21
     wait visTime ms

   Repeat 3                   ;Frame 15. Quickmoves to A28, B4, C10, D21
     AG2C
     ACG1
     AG12
   End Repeat
     AG2C
     wait visTime ms
   Repeat 3
     BG2C
     BCG1
     BG12
   End Repeat
     BG2C
     wait visTime ms
   Repeat 2
     CCG2
     CG21
     CG1C
   End Repeat
     wait visTime ms
     DG1C
     DCG2
     wait visTime ms

   howmany = howmany * 2                ;double the number of loops
    If howmany > 64 then howmany = 1    ;resets the number of loops
   visTime = visTime / 2                ;half the time the pin is visible
    If visTime < 2 then visTime = 128   ;resets the time the pin is visible

  Next counter
Loop

End  ;*************************************************************************************

;Interrupt handler;detect which key pressed
Sub Switches

  wait 30 ms                               ;debounce
  If Switch1 = 0 then goto Animation1
  If Switch2 = 0 then goto Animation2
  If Switch3 = 0 then goto Animation3
  If Switch4 = 0 then goto Animation4
  If Switch5 = 0 then goto Animation5

End sub

TubeA_Quickmove_Subroutines:
Sub ACG1 ;Cathode to G1 (clockwise)
set TubeAG1 on : wait 100 us
End sub

Sub AG12 ;G1 to G2 (clockwise)
set TubeAG2 on : wait 20 us : set TubeAG1 off : wait 100 us
End sub

Sub AG2C ;G2 to Cathode (clockwise)
set TubeAG2 off : wait 80 us
End sub

Sub AG21 ;G2 to G1 (counterclockwise)
set TubeAG1 on : wait 20 us : set TubeAG2 off : wait 100 us
End sub

Sub AG1C ;G1 to Cathode (counter clockwise)
set TubeAG1 off : wait 80 us
End sub

Sub ACG2 ;Cathode to G2 (counterclockwise)
set TubeAG2 on : wait 100 us
End sub

TubeB_Quickmove_Subroutines:
Sub BCG1 ;Cathode to G1 (clockwise)
set TubeBG1 on : wait 100 us
End sub

Sub BG12 ;G1 to G2 (clockwise)
set TubeBG2 on : wait 20 us : set TubeBG1 off : wait 100 us
End sub

Sub BG2C ;G2 to Cathode (clockwise)
set TubeBG2 off : wait 80 us
End sub

Sub BG21 ;G2 to G1 (counterclockwise)
set TubeBG1 on : wait 20 us : set TubeBG2 off : wait 100 us
End sub

Sub BG1C ;G1 to Cathode (counter clockwise)
set TubeBG1 off : wait 80 us
End sub

Sub BCG2 ;Cathode to G2 (counterclockwise)
set TubeBG2 on : wait 100 us
End sub

TubeC_Quickmove_Subroutines:
Sub CCG1 ;Cathode to G1 (clockwise)
set TubeCG1 on : wait 100 us
End sub

Sub CG12 ;G1 to G2 (clockwise)
set TubeCG2 on : wait 20 us : set TubeCG1 off : wait 100 us
End sub

Sub CG2C ;G2 to Cathode (clockwise)
set TubeCG2 off : wait 80 us
End sub

Sub CG21 ;G2 to G1 (counterclockwise)
set TubeCG1 on : wait 20 us : set TubeCG2 off : wait 100 us
End sub

Sub CG1C ;G1 to Cathode (counter clockwise)
set TubeCG1 off : wait 80 us
End sub

Sub CCG2 ;Cathode to G2 (counterclockwise)
set TubeCG2 on : wait 100 us
End sub

TubeD_Quickmove_Subroutines:
Sub DCG1 ;Cathode to G1 (clockwise)
set TubeDG1 on : wait 100 us
End sub

Sub DG12 ;G1 to G2 (clockwise)
set TubeDG2 on : wait 20 us : set TubeDG1 off : wait 100 us
End sub

Sub DG2C ;G2 to Cathode (clockwise)
set TubeDG2 off : wait 80 us
End sub

Sub DG21 ;G2 to G1 (counterclockwise)
set TubeDG1 on : wait 20 us : set TubeDG2 off : wait 100 us
End sub

Sub DG1C ;G1 to Cathode (counter clockwise)
set TubeDG1 off : wait 80 us
End sub

Sub DCG2 ;Cathode to G2 (counterclockwise)
set TubeDG2 on : wait 100 us
End sub

;-----------------------------------------------------------------------
TubeA_Visible_Subroutines:
Sub AVCG1 ;Cathode to G1 (clockwise)
set TubeAG1 on : wait 25 ms
End sub

Sub AVG12 ;G1 to G2 (clockwise)
set TubeAG2 on : wait 20 us : set TubeAG1 off : wait 25 ms
End sub

Sub AVG2C ;G2 to Cathode (clockwise)
set TubeAG2 off : wait 20 ms
End sub

Sub AVG21 ;G2 to G1 (counterclockwise)
set TubeAG1 on : wait 20 us : set TubeAG2 off : wait 25 ms
End sub

Sub AVG1C ;G1 to Cathode (counterclockwise)
set TubeAG1 off : wait 20 ms
End sub

Sub AVCG2 ;Cathode to G2 (counterclockwise)
set TubeAG2 on : wait 25 ms
End sub

TubeB_Visible_Subroutines:
Sub BVCG1 ;Cathode to G1 (clockwise)
set TubeBG1 on : wait 25 ms
End sub

Sub BVG12 ;G1 to G2 (clockwise)
set TubeBG2 on : wait 20 us : set TubeBG1 off : wait 25 ms
End sub

Sub BVG2C ;G2 to Cathode (clockwise)
set TubeBG2 off : wait 20 ms
End sub

Sub BVG21 ;G2 to G1 (counterclockwise)
set TubeBG1 on : wait 20 us : set TubeBG2 off : wait 25 ms
End sub

Sub BVG1C ;G1 to Cathode (counterclockwise)
set TubeBG1 off : wait 20 ms
End sub

Sub BVCG2 ;Cathode to G2 (counterclockwise)
set TubeBG2 on : wait 25 ms
End sub

TubeC_Visible_Subroutines:
Sub CVCG1 ;Cathode to G1 (clockwise)
set TubeCG1 on : wait 25 ms
End sub

Sub CVG12 ;G1 to G2 (clockwise)
set TubeCG2 on : wait 20 us : set TubeCG1 off : wait 25 ms
End sub

Sub CVG2C ;G2 to Cathode (clockwise)
set TubeCG2 off : wait 20 ms
End sub

Sub CVG21 ;G2 to G1 (counterclockwise)
set TubeCG1 on : wait 20 us : set TubeCG2 off : wait 25 ms
End sub

Sub CVG1C ;G1 to Cathode (counterclockwise)
set TubeCG1 off : wait 20 ms
End sub

Sub CVCG2 ;Cathode to G2 (counterclockwise)
set TubeCG2 on : wait 25 ms
End sub

TubeD_Visible_Subroutines:
Sub DVCG1 ;Cathode to G1 (clockwise)
set TubeDG1 on : wait 25 ms
End sub

Sub DVG12 ;G1 to G2 (clockwise)
set TubeDG2 on : wait 20 us : set TubeDG1 off : wait 25 ms
End sub

Sub DVG2C ;G2 to Cathode (clockwise)
set TubeDG2 off : wait 20 ms
End sub

Sub DVG21 ;G2 to G1 (counterclockwise)
set TubeDG1 on : wait 20 us : set TubeDG2 off : wait 25 ms
End sub

Sub DVG1C ;G1 to Cathode (counterclockwise)
set TubeDG1 off : wait 20 ms
End sub

Sub DVCG2 ;Cathode to G2 (counterclockwise)
set TubeDG2 on : wait 25 ms
End sub

;Below are all 6 Quickmoves and Visible moves, for reference
;Note "X" must be replaced by A, B, C, or D to indicate which tube is being referenced

;QUICKMOVES
;set TubeXG1 on : wait 100 us                                     ;Cathode to G1 (clockwise)
;set TubeXG2 on : wait 20 us : set TubeAG1 off : wait 100 us      ;G1 to G2 (clockwise)
;set TubeXG2 off : wait 80 us                                     ;G2 to Cathode (clockwise)
;set TubeXG1 on : wait 20 us : set TubeAG2 off : wait 100 us      ;G2 to G1 (counterclockwise)
;set TubeXG1 off : wait 80 us                                     ;G1 to Cathode (counter clockwise)
;set TubeXG2 on : wait 100 us                                     ;Cathode to G2 (counterclockwise)

;VISIBLE MOVES
;set TubeXG1 on : wait 25 ms                                     ;Cathode to G1 (clockwise)
;set TubeXG2 on : wait 20 us : set TubeAG1 off : wait 25 ms      ;G1 to G2 (clockwise)
;set TubeXG2 off : wait 20 ms                                    ;G2 to Cathode (clockwise)
;set TubeXG1 on : wait 20 us : set TubeAG2 off : wait 25 ms      ;G2 to G1 (counterclockwise)
;set TubeXG1 off : wait 20 ms                                    ;G1 to Cathode (counterclockwise)
;set TubeXG2 on : wait 25 ms                                     ;Cathode to G2 (counterclockwise)