Jump to content

dungpt29

Members
  • Content Count

    29
  • Joined

  • Last visited

Everything posted by dungpt29

  1. Hi sparkynerd, Because you are new to PHP so I will work out a solution that is most suitable to you and is just based on your own code. First, you need to create a new text file named LED_Status.txt that is in the same folder containing your graphic.txt. This file, just as its name, is specialized in containing the status of your LED that is either ON or OFF. The initial status filled in file should be OFF. The code to solve your problem should be as the following: <?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 =""; // Reading the data from text file $LED_Status_Temp = file_get_contents('LED_Status.txt'); $LED2 = $LED_Status_Temp; // $LED2 is assigned the current status of your LED } 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"; // set and write data to text file $fp = fopen('LED_Status.txt','w'); fwrite($fp,$LED2); // update current LED status } 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('LED_Status.txt','w'); fwrite($fp,$LED2); // update current LED status } ///////////////////////////////////////////////////////////////////////////////////////////// // 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); ?>
  2. I reckon the cause is that you have not processed the case of none of your buttons is pressed yet. In that case $LED2 is an empty string and thereby $image is not defined.
×
×
  • 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.