Last active
October 15, 2023 11:59
-
-
Save jenschr/a199aabfac4750d3311882aaa1c84165 to your computer and use it in GitHub Desktop.
Basic HTML page for talking to Particle Photon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ----------------------------------- | |
// Control 8 LEDs over the Internet | |
// Hook the LED's to a Particle Photon | |
// and use this script with Build. | |
// ----------------------------------- | |
int led1 = D0; | |
int led2 = D1; | |
int led3 = D2; | |
int led4 = D3; | |
int led5 = D4; | |
int led6 = D5; | |
int led7 = D6; | |
int led8 = D7; | |
int val1 = LOW; | |
int val2 = LOW; | |
int val3 = LOW; | |
int val4 = LOW; | |
int val5 = LOW; | |
int val6 = LOW; | |
int val7 = LOW; | |
int val8 = LOW; | |
int toggleit(String param); | |
void setup() { | |
// Set pins to outputs | |
pinMode(led1, OUTPUT); | |
pinMode(led2, OUTPUT); | |
pinMode(led3, OUTPUT); | |
pinMode(led4, OUTPUT); | |
pinMode(led5, OUTPUT); | |
pinMode(led6, OUTPUT); | |
pinMode(led7, OUTPUT); | |
pinMode(led8, OUTPUT); | |
Particle.function("toggle", toggleit); | |
digitalWrite(led5, HIGH); | |
} | |
void loop() { | |
} | |
int toggleit(String param) | |
{ | |
int ledToToggle = param.toInt(); | |
if( ledToToggle == 1 ){ | |
if( val1 == HIGH){ | |
val1 = LOW; | |
} else { | |
val1 = HIGH; | |
} | |
} else if( ledToToggle == 2 ){ | |
if( val2 == HIGH){ | |
val2 = LOW; | |
} else { | |
val2 = HIGH; | |
} | |
} else if( ledToToggle == 3 ){ | |
if( val3 == HIGH){ | |
val3 = LOW; | |
} else { | |
val3 = HIGH; | |
} | |
} else if( ledToToggle == 4 ){ | |
if( val4 == HIGH){ | |
val4 = LOW; | |
} else { | |
val4 = HIGH; | |
} | |
} else if( ledToToggle == 5 ){ | |
if( val5 == HIGH){ | |
val5 = LOW; | |
} else { | |
val5 = HIGH; | |
} | |
} else if( ledToToggle == 6 ){ | |
if( val6 == HIGH){ | |
val6 = LOW; | |
} else { | |
val6 = HIGH; | |
} | |
} else if( ledToToggle == 7 ){ | |
if( val7 == HIGH){ | |
val7 = LOW; | |
} else { | |
val7 = HIGH; | |
} | |
} else if( ledToToggle == 8 ){ | |
if( val8 == HIGH){ | |
val8 = LOW; | |
} else { | |
val8 = HIGH; | |
} | |
// setup via ifttt: https://ifttt.com/myrecipes/personal/36862361 | |
} else if( param == "ringeklokke" ){ | |
if( val4 == HIGH){ | |
val4 = LOW; | |
} else { | |
val4 = HIGH; | |
} | |
} else { | |
allOff(); | |
} | |
setAll(); | |
return ledToToggle; | |
} | |
void allOff() { | |
val1 = LOW; | |
val2 = LOW; | |
val3 = LOW; | |
val4 = LOW; | |
val5 = LOW; | |
val6 = LOW; | |
val7 = LOW; | |
val8 = LOW; | |
setAll(); | |
} | |
void setAll() { | |
digitalWrite(led1, val1); | |
digitalWrite(led2, val2); | |
digitalWrite(led3, val3); | |
digitalWrite(led4, val4); | |
digitalWrite(led5, val5); | |
digitalWrite(led6, val6); | |
digitalWrite(led7, val7); | |
digitalWrite(led8, val8); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Turn on/off eight LEDs connected to Particle Photon pins D0...D7 --> | |
<!DOCTYPE> | |
<html> | |
<head> | |
<title>on/off</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script> | |
<script type="text/javascript"> | |
function submitform( formNum ) | |
{ | |
var dataObj = {}; | |
dataObj.args = formNum; | |
// the first string of random chars is the ID of your Photon. You can find this via build.particle.io by clicking the devices icon | |
// the second string (access_token) can be found under the Settings icon. When you regenerate the token, all former versions cease to work | |
$.post( "https://api.particle.io/v1/devices/28002c001847341128333633/toggle?access_token=124ae13ec936ee7d6fb5e633787cf8d207287d62", dataObj, function( dataObj ) { | |
$( "#result" ).html( JSON.stringify(dataObj) ); | |
}); | |
return false; | |
} | |
</script> | |
</head> | |
<body> | |
<center> | |
<div> | |
<a href="javascript: submitform(1)">- 1 -</a> | |
<a href="javascript: submitform(2)">- 2 -</a> | |
<a href="javascript: submitform(3)">- 3 -</a> | |
<a href="javascript: submitform(4)">- 4 -</a> | |
<a href="javascript: submitform(5)">- 5 -</a> | |
<a href="javascript: submitform(6)">- 6 -</a> | |
<a href="javascript: submitform(7)">- 7 -</a> | |
<a href="javascript: submitform(8)">- 8 -</a> | |
<a href="javascript: submitform(10)">- off -</a> | |
</div> | |
<div id="result"></div> | |
</center> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment