SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm running into problems with the following script I have. I would appreciate any help you can give. I need the following features, but am lost as to how to implement them and how to create the functions.

    1) When the Power is turned off, the time displays (I already have a function created for the time called time())When the power is turned on, the current station is displayed. However, it does not need to play any music. I will work on that later.

    2) Pressing the AM/FM button will change it to either AM or FM. (I have the AM stations all set which are incremented by 10, but how can I get it to display FM stations ranging from 88 to 108 incremented by 0.1?)

    3) The volume buttons change the volume display from 1 to 10 in increments of 1, shown by dashes.

    4) I also need help with this radio remembering its settings. For instance, if the radio is set at FM 88 at a volume of 3, when the radio is turned off then back on again, these same settings display. Is this done with cookies? If so, how?



    Here is the script I have so far:

    SONG = new Array()
    var x=540
    for (x=540; x<=1600; x=x+10)

    function prev(){
    if (x>540)
    { x=x-10
    document.midi.typein.value=x
    }
    }

    function next(){
    if (x<1600)
    { x=x+10
    document.midi.typein.value=x
    }
    }

    function go(){
    if (x != 0){
    location.href='http://home.dmv.com/~lcrocket/SONG'+x+'.MID'
    }
    }

    function display(){
    document.midi.typein.value="~ display time ~"
    }


    <BODY Bgcolor="#ffffff" onload="display()">
    <FONT face="arial,helvetica">
    <FORM Name="midi">
    <INPUT
    TYPE=Button Value="POWER" Align=left onclick="go()">

    <br>
    <br>
    <INPUT TYPE=Button Value="AM/FM" Align=left>
    <INPUT NAME="typein" TYPE="text" SIZE="15" ALIGN=top>
    <INPUT TYPE=Button Value="<<" Align=left onclick="prev()">
    Tune
    <INPUT TYPE=Button Value=">>" Align=left onclick="next()">
    <br>
    <input type=button value=" - " onClick="MIDI_decVolume(5); blur();">
    Vol
    <input type=button value=" + " onClick="MIDI_incVolume(5); blur();">
    <input name="txtVolume" type=text size="10" maxlength="10" value=""
    onFocus="blur();">
    </FORM>


    Again, I would be very greatful for any help you can give. Thanks!

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What kind of interface are you looking to provide? How should these controls display the channel/volume? Are you looking for a DHTML solution?
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not concerned about the interface yet. My primary concern building the functions and make sure they are working properly. Thanks.

  4. #4
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Umm okay, but how can you make functions that work properly if they don't do anything?

    Generally, you should have a variable for each piece of 'state information' that your radio has. So you should have a variable for the volume, a variable for the station (probably one each for AM and FM), a variable for AM/FM, a variable for power (ON or OFF).

    Then just make your functions update the appropriate variable, then call some kind of "updateView()" function. This function will use all of the state variables to update what the user sees and hears. By using a single function to update the view, you save yourself the trouble of worrying about all the interactions between the functions.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  5. #5
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is an updated version of the script. (I don't need any music yet, just for the functions to do what they're supposed to.) The AM stations work fine. When the AM/FM button is pressed, an FM station displays, but clicking on the << or >> brings it back to AM. I don't know how to get this to stay on FM. Clicking on the AM/FM button again should switch the band again, but it doesn't. Also, the volume should display an extra dash when it is increased, and remove one when the volume is decreased. When the radio is turned off, the time should display in the same place the stations display. And when the power is turned on, the time should disapper and the stations should display. The settings of the radio should be saved when a user comes back to it and turns it back on. My main concerns for now are getting the stations and the volume to work properly, and the power button to function as intended. This is all still pretty new to me and as you can see I'm having quite a bit of trouble. Thanks a lot for your help Kevin.






    <Script Language="JavaScript">

    function show()
    {
    var Digital=new Date()
    var hours=Digital.getHours()
    var minutes=Digital.getMinutes()
    var seconds=Digital.getSeconds()
    var dn="AM"
    if (hours>12)
    {
    dn="PM"
    hours=hours-12
    //this is so the hours written out is
    //in 12-hour format, instead of the default //24-hour format.
    }
    if (hours==0)
    hours=12
    //this is so the hours written out
    //when hours=0 (meaning 12a.m) is 12
    if (minutes<=9)
    minutes="0"+minutes
    if (seconds<=9)
    seconds="0"+seconds
    document.midi.time.value=
    hours+":"+minutes+":"+seconds+" "+dn
    setTimeout("show()",1000)
    }


    AM = new Array()
    var x=540;
    for (x=540; x<1600; x=x+10)


    FM = new Array()
    var y=88;
    for (y=88; y<180; y=y+0.1)


    function prev(){
    if (y>88)
    { y=y-0.1
    document.midi.typein.value=y
    }
    if (x>540)
    { x=x-10
    document.midi.typein.value=x
    }
    }


    function next(){
    if (y<180)
    { y=y+0.1
    document.midi.typein.value=y
    }
    if (x<1600)
    { x=x+10
    document.midi.typein.value=x
    }
    }


    function amfm(){
    if (AM = new Array()) {
    document.midi.typein.value=x}
    if (FM = new Array()) {
    document.midi.typein.value=y}

    }


    function volUp() {
    for (vol=0; vol<=10; ++vol)
    document.midi.txtVolume.value=("-")
    }

    function volDown() {
    document.midi.txtVolume.value=("")
    }


    </Script>

    <body bgcolor=white onload="show()">

    <FORM Name="midi">

    <input type=text name="time" size="10"><br>
    <INPUT TYPE=Button name="power" Value="POWER" Align=left><br><br>


    <INPUT TYPE=button value="AM/FM" onclick="amfm()">

    <INPUT NAME="typein" TYPE="text" SIZE="10" ALIGN=top>

    <INPUT TYPE=Button Value="<<" Align=left onclick="prev()">
    Tune
    <INPUT TYPE=Button Value=">>" Align=left onclick="next()">

    <input name="txtVolume" type=text size="10" maxlength="10" value="---">
    <input type=button value=" - " onClick="volDown()">
    Vol
    <input type=button value=" + " onClick="volUp()">

    </FORM>

    </body>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •