// Blinking LED
// Connecting Practice and controlling LEDS directly
// Include Particle Device OS APIs
#include "Particle.h"
// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);
// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
SerialLogHandler logHandler(LOG_LEVEL_INFO);
// First make a variable
// This is the shorthand that will be used throughout the program
int led1 = D2; // Instead of writing D0 over and over again, we will use led1
// I will need to wire an led to this one to see it blink
int led2 = D3;
// setup() runs once, when the device is first turned on
void setup() {
// We want to tell the Photon that we'll use
// D2 as an output pin.
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
// Put initialization like pinMode and begin functions here
}
// loop() runs over and over again, as quickly as it can execute.
void loop() {
// Basics Demo
// First... On
// digitalWrite(led1, HIGH); // Turn ON the LED pins
// delay(1000); // Wait for 1000mS = 1 second
// // Now... Off
// digitalWrite(led1, LOW); // Turn OFF the LED pins
// delay(1000); // Wait for 1000mS = 1 second
// rinse + repeat
// The core of your code will likely live here.
// Example: Publish event to cloud every 10 seconds. Uncomment the next 3 lines to try it!
// Log.info("Sending Hello World to the cloud!");
// Particle.publish("Hello world!");
// delay( 10 * 1000 ); // milliseconds and blocking - see docs for more info!
// Exercise 1
// digitalWrite(led1, HIGH); // Turn ON the LED pins
// delay(3000); // Wait for 3000mS = 3 second
// // Now... Off
// digitalWrite(led1, LOW); // Turn OFF the LED pins
// delay(3000); // Wait for 3000mS = 3 second
//Exercise 2
// digitalWrite(led1, HIGH); // Turn ON the LED pins
// delay(500); // Wait for 500mS = .5 second
// // Now... Off
// digitalWrite(led1, LOW); // Turn OFF the LED pins
// delay(500); // Wait for 500mS = .5 second
// digitalWrite(led1, HIGH); // Turn ON the LED pins
// delay(500); // Wait for 500mS = .5 second
// // Now... Off
// digitalWrite(led1, LOW); // Turn OFF the LED pins
// delay(500); // Wait for 500mS = .5 second
// digitalWrite(led1, HIGH); // Turn ON the LED pins
// delay(500); // Wait for 500mS = .5 second
// // Now... Off
// digitalWrite(led1, LOW); // Turn OFF the LED pins
// delay(500); // Wait for 500mS = .5 second
// digitalWrite(led1, HIGH); // Turn ON the LED pins
// delay(500); // Wait for 500mS = .5 second
// // Now... Off
// digitalWrite(led1, LOW); // Turn OFF the LED pins
// delay(500); // Wait for 500mS = .5 second
// digitalWrite(led1, HIGH); // Turn ON the LED pins
// delay(500); // Wait for 500mS = .5 second
// // Now... Off
// digitalWrite(led1, LOW); // Turn OFF the LED pins
// delay(3000); // Wait for 500mS = 3 second
// Exercise 3
// First... On
digitalWrite(led1, HIGH); // Turn ON the LED1 pins
delay(1000); // Wait for 2000mS = 1 second
// Now... Off
digitalWrite(led1, LOW); // Turn OFF the LED1 pins
delay(0); // Wait for 0mS = 0 second
digitalWrite(led2, HIGH); // Turn ON the LED2 pins
delay(1000); // Wait for 1000mS = 1 second
// Now... Off
digitalWrite(led2, LOW); // Turn OFF the LED1 pins
delay(0); // Wait for 0mS = 0 second
}
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. .