//LAB 1 - BASE SET UP
//GLOBAL VARIABLES
// Set up global variable for pin so that any configuration changes
// changes can easily and quickly be applied throughout the code
int led = D2;
//Set up status variable to check the state of the power - is it on
//or is it off?
bool status = LOW;
//PROGRAM
//Setup function configures the initial state of the microcontroller
//In this case, the microcontroller will be set to off when
//the program first runs.
void setup() {
pinMode(led, OUTPUT);
//This code makes the functiona accessible via the cloud
Particle.function("ledControl", ledControl);
}
//Loop function repeats the actions in it repeatedly
//until the microcontroller is turned off (removed from power)
void loop() {
digitalWrite(led, status);
delay(500);
}
//If the command "on" is received, the LED is turned on
//If the command "off" is received, the LED is turned off
int ledControl (String command) {
if(command.equals("on")) {
status = HIGH;
return 1; // This indicates that the 'on' command was successfully received and exectued
}
if(command.equals("off")) {
status = LOW;
return -1; // This indicates that the 'off' command was successfully received and exectued
}
return 401; //This indicates that there is an error
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .