logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

[Bascom] Mały problem z funkcjami

Gibol 06 Gru 2009 03:32 1140 1
REKLAMA
  • #1 7350810
    Gibol
    Poziom 17  
    Chciałem sobie dostosować bascomowe polecenie Sound (pin, pulses, periodes) do PeCetowego Beep(f,t) w tym celu sobie napisałem 2 funkcje ale coś nie zabardzo to działa. Pierwszy raz w ogóle używam funkcji w bascomie, proszę o pomoc.

    
    $regfile = "m32def.dat"
    $crystal = 16000000                                         '16MHz
    
    
    Dim Pulses As Single
    Dim Periodes As Single
    Dim F As Integer
    Dim T As Single
    
    
    Speaker Alias Portb.0
    
     Config Portb.0 = Output
    
     Declare Function Per(byval F As Integer ) As Single
    
     Declare Function Pul(byval Periodes As Single , T As Single) As Single
    
    Const A = 440
    Const A2 = 880
    
    Periodes = Per(f)
    Pulses = Pul(periodes , T)
    
    
    Do
    F = A
    T = 400
    
    Sound Speaker , Pulses , Periodes
    Waitms 100
    F = A2
    T = 200
    
    Sound Speaker , Pulses , Periodes
    Waitms 200
    Loop
    
    
    
    
    
        Function Per(byval F As Integer ) As Single
    
        Local P As Single
        Local Fc As Single
        Local K As Single
    
        Fc = 16000000
        K = F * 12
    
        P = Fc / K
        P = Round(p)
    
    
        Per = P
        End Function
    
    
        Function Pul(byval Periodes As Single , T As Single) As Single
    
        Local K As Single
        Local Ts As Single
        Local Tsf As Single
        Local P As Single
        Local Fc As Single
    
    
        Fc = 16000000
        K = 12 * Periodes
        Ts = T / 1000
        Tsf = Ts * Fc
        P = Tsf / K
        P = Round(p)
        Pul = P
        End Function
    
  • REKLAMA
  • #2 7350905
    Vietech
    Poziom 13  
    ściągnij z neta Help do bascom w j. polskim tam jest to polecenie ładnie i łopatologicznie opisane, jak wiele innych. Ciekawe lektury pisze też Marcin wiązania (też dostępne w formacie PDF.)
REKLAMA