Skip to content

Instantly share code, notes, and snippets.

@atypical
Created May 1, 2012 23:06
Show Gist options
  • Save atypical/2572204 to your computer and use it in GitHub Desktop.
Save atypical/2572204 to your computer and use it in GitHub Desktop.
The PHP now controls a switch. The HTML uses: http://jsfiddle.net/ThomasBurleson/3SXtf/embedded/result/
<!DOCTYPE html>
<html>
<head>
<title>Dope</title>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="js/wait.js"></script>
<script type="text/javascript" language="javascript">
$(function() {
$('fireButton').click(function(){
    
$.wait(100,function(){
    var url = "php/switch.php?setDigitalOutput&pin=6&output=255";
$.get(url)
 })
 .done( function() {
    var url = "php/switch.php?setDigitalOutput&pin=6&output=0";
$.get(url)
 });
});
});
</script>
</head>
<body>
<p>
</p>
<button id="fireButton">FIRE</button>
</body>
</html>​
<?php
include_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'_config.php');
include_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'teleduino328_php.php');
if(isset($_SERVER['HTTP_HOST']))
{
echo "<pre>";
}
$Teleduino328PHP = new Teleduino328PHP();
$Teleduino328PHP->setModeEthernetClientProxy($config['ethernet_client_proxy_key']);
$result = $Teleduino328PHP->getPresets();
if($result['result'])
{
$presets = $result['values'];
$presets['pin_modes'][6] = 2; // Set pin 6 mode to 'PWM'
$result = $Teleduino328PHP->setPresets($presets);
}
$pin = isset($_GET['pin']) ? ((int) $_GET['pin']) : 0; // Set to pin 6 = fire
$output = isset($_GET['output']) ? ((int) $_GET['output']) : 0; // Output PWM (0 - 255)
$result = $Teleduino328PHP->setPwmOutput($pin, $output);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment