Jump to content

sparkynerd

New Members
  • Posts

    3
  • Joined

  • Last visited

sparkynerd's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. That makes sense... so is there a way to process the string that is stored in the text file as soon as the page is loaded the first time? I am trying random things, but no success yet...
  2. I have a simple web page with 2 buttons that change an icon to red or green based on which button is pressed. When the button is pressed, the variable is stored in a text file, and then recalled to display the proper color icon. (When "Power On" is pressed, the icon turns red, and when "Power Off" is pressed, it turns green.) The problem I have is this: When the page is first loaded, the graphic is blank, until a button is pressed, and then the icon displays properly. The text file with the stored variable is always available on the server, but I cant figure out why the page isnt working properly. I know my webpage is probably full of other problems, but I am a real noob, trying to create my home automation webpage... If you are wondering why I am storing the variable in a text file, it was my way of saving this variable, so that another user could open the same webpage at another time, on another computer, and be able to see the correct status icon. if there is a better way (without Java), please let me know! Here is my code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <?php ///////////////////////////////////////////////////////////////////////////////////////////// // Check of LED2 is set. If it is, then use it if (isset($_POST["LED2"])) { $LED2= $_POST["LED2"]; //echo "<b>$LED2</b>"; } else { $LED2 =""; } if ($LED2 == "ON") { // Set led2 ON by calling the Arduino using fopen $h = @fopen("http://192.168.5.21/?LED=T", "rb"); $image = "/Graphics/LED_red.bmp"; } else if ($LED2 == "OFF") { // Set led2 OFF by calling the Arduino using fopen $h= @fopen("http://192.168.5.21/?LED=F", "rb"); $image = "/Graphics/LED_green.bmp"; } ///////////////////////////////////////////////////////////////////////////////////////////// // set and write data to text file { $fp = fopen('graphic.txt','w'); fwrite($fp,$image); } ///////////////////////////////////////////////////////////////////////////////////////////// // Reading the data from text file $graphictemp = file_get_contents('graphic.txt'); $graphic = ($graphictemp); ?> <head> <style type="text/css"> body { font: 100% Verdana, Arial, Helvetica, sans-serif; background: #666666; margin: 0; padding: 0; text-align: center; color: #000000; } .newStyle1 { float: left; } .auto-style1 { color: #FFFFFF; font-size: 20px; } </style> <title>Audio Control</title> </head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <body> <form action="" method="post" > <fieldset style="display:inline; border:none; padding:0px; margin:0px; vertical-align:top; class="newStyle1" style="height: 450px" > <legend align="center" class="auto-style1">Amplifier <img name="LED" src="<?=$graphic?>" width="12" height="12" alt="" style="background-color: #FFFFFF" /></legend> <br/> <button name="LED2" style="height: 1.8em; width: 10em; font-size: 16px;" value="ON" type="submit">Power On</button> <br /> <br /> <button name="LED2" style="height: 1.8em; width: 10em; font-size: 16px;" value="OFF" type="submit">Power Off</button> <br /> <br /> </fieldset> </form> </body> </html>
  3. I have created a PHP web page that allows me to control a serial device (a speaker selector matrix), and an Arduino (to switch an amplifier off and on) over my network. I am trying to make it so the text color changes on what ever button is pressed. The button presses are stored as a variable and then POSTed. I would like the text on the current button selected to turn red. There are 5 separate sets of buttons, so each set could have a button with red text at any time. Eventually, I would like to have a graphic next to the button which would change based on a button press. (baby steps!) Attached is the web page. Please keep any answers in laymans terms, since I am a real PHP noob! This webpage is the result of A LOT of trial and error, but it works! Any suggestions are welcome! audio.php
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.