Simulated Dekatron Radiation Meter

Several of us have been involved in a discussion of writing code to analyse the blips/clicks of a Geiger counter. Of interest are the individual pulses, their rate, and the average interval and distribution statistics. For old times' sake I did the opposite- recreating the lovely orange glow of neon tubes.

Dekatrons have 30 electrodes arranged as 3 connected sets of ten. By suitably phasing the drive the glow transfers to the nearest phase1 electrode then to phase2, before relaxing back to the count electrode, but one place advanced.

Once divided down to rates below a few per second, an electromechanical counter can cope.


Code

    '   Dekatron display

    nomainwin

    WindowWidth  = 881
    WindowHeight = 252

    button #wg.b1 "Hold ", cnt, LR, 787, 120
    button #wg.b2 "Reset", rst, LR, 787,  80

    open "Dekatron Geiger Counter" for graphics_nsb as #wg

    #wg "down ; fill 22 84 164"
    #wg "trapclose quit"

    global radius, xa, ya   '   centre and radius of a tube
    global pUnits, pTens, pThous, mechCount
    global state
    global x1, x2, x3, y1, y2, y3

    state       =  1

    radius      = 60
    xa          =224
    ya          =110

    angUnits    =  0
    angTens     =  0
    angThous    =  0

    mechCount   =  0

    loadbmp "scr", "3deka.bmp"
    #wg "drawbmp scr ";   200; " ";   0

    loadbmp "lit",         "lit.bmp"
    loadbmp "unlit",     "unlit.bmp"

    loadbmp "6digits", "zeroed.bmp"
    #wg "drawbmp 6digits "; 26; " "; 28

    #wg "font Courier_New bold 22"
    #wg "color white ; backcolor black"


    for i =1 to 100000
        scan
        D   =30 +int( 500 *rnd( 1))
        calldll #kernel32,"Sleep", D as long, re as void

        playwave "click.wav", async
        #wg "drawbmp unlit "; 90 + x1; " "; y1
        #wg "drawbmp unlit "; 90 + x2; " "; y2
        #wg "drawbmp unlit "; 90 + x3; " "; y3
        if state =1 then call updateDekatrons
        if i <10 then #wg "getbmp scr 0 0 880 230": bmpsave "scr", "S/screen" +str$( i) +".bmp"
    next i

    wait

    sub updateDekatrons
        pUnits  =pUnits +1
        if pUnits =10 then pUnits =0: pTens =pTens +1
        x1      =int( 3 *xa +radius *sin( 36 *pUnits *3.14159265 /180))
        y1      =int( 1 *ya -radius *cos( 36 *pUnits *3.14159265 /180))
        #wg "drawbmp lit "; 90 + x1; " "; y1

        if pTens  =10 then pTens =0: pThous =pThous +1
        x2      =int( 2 *xa +radius *sin( 36 *pTens *3.14159265 /180))
        y2      =int( 1 *ya -radius *cos( 36 *pTens *3.14159265 /180))
        #wg "drawbmp lit "; 90 + x2; " "; y2

        if pThous =10 then pThous =0: mechCount =mechCount +1
        x3      =int( 1 *xa +radius *sin( 36 *pThous *3.14159265 /180))
        y3      =int( 1 *ya -radius *cos( 36 *pThous *3.14159265 /180))
        #wg "drawbmp lit "; 90 +x3; " "; y3

        #wg "up ; goto "; 25; " "; 51
        #wg "down"
        #wg "\ "; right$( "000000" +str$( mechCount), 6) +" "

        calldll #kernel32,"Sleep", 20 as long, re as void

        '#wg "drawbmp unlit "; 90 + x1; " "; y1
        '#wg "drawbmp unlit "; 90 + x2; " "; y2
        '#wg "drawbmp unlit "; 90 + x3; " "; y3

        scan
        '#wg "drawbmp unlit "; x1; " "; y1
    end sub

    sub rst k$
         #wg "up ; goto "; 25; " "; 51
         #wg "down"
         #wg "\ "; right$( "000000" +str$( mechCount), 6) +" "
         mechCount  =0
         pUnits     =0
         pTens      =0
         pThous     =0
         state      =0
    end sub

    sub cnt k$
        if state =0 then state =1: #wg.b1 "Hold" else state =0: #wg.b1 "Run  "
    end sub

   sub quit h$ 'End the program
        close #wg
        end
    end sub




The LB code and bitmaps/wav files are available as Dekatron