-
-
Save dyadica/c5040c6a5f6cac533be6ab8936b29d0d to your computer and use it in GitHub Desktop.
Photon Control of MOSFET
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
// The handler for the subscription | |
void myHandler(String event, String data) | |
{ | |
if(data == "on") | |
{ | |
digitalWrite(mosfet, HIGH); | |
} | |
if(data == "off") | |
{ | |
digitalWrite(mosfet, LOW); | |
} | |
} |
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
// Loop through the program | |
void loop() | |
{ | |
// Check to see if the button is pressed | |
// or not. The use of flags ensures that | |
// only a singular event is called for | |
// each state. | |
if(digitalRead(buttonPin) == LOW) | |
{ | |
// The button is released. Check against the flag | |
// to see if it has already been set. If so return. | |
if(pressed == false) | |
return; | |
// The flag has not been set so set it now. | |
pressed = false; | |
// Publish the off event. | |
Particle.publish("mosToggle", "off"); | |
} | |
else if(digitalRead(buttonPin) == HIGH) | |
{ | |
// The button is pressed. Check against the flag | |
// to see if it has already been set. If so return. | |
if(pressed == true) | |
return; | |
// The flag has not been set so set it now. | |
pressed = true; | |
// Publish the on event. | |
Particle.publish("mosToggle", "on"); | |
} | |
// Use a delay to slow down the loop; thus allowing | |
// time for operations to complete. | |
delay(period); | |
} |
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
void setup() | |
{ | |
// Set the mosfet pin (set as D3) as an | |
// output. | |
pinMode(mosfet, OUTPUT); | |
// Set mosfet to off by writing | |
// LOW to the pin. | |
digitalWrite(mosfet, LOW); | |
// Register the subscription and assign | |
// a handler for it | |
Particle.subscribe("mosToggle", myHandler); | |
} |
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
This Gist contains code developed as part of the IoST project. The code enables the control of high powered devices such as Motors and Solenoids via the Photon microcontroller. This code is a reworking of the Arduino mosfet control developed as part of the Artist Residency where a prototype was developed that utilised a MOSFET to control power to a heated element. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment