Skills Dev I: Simple Internet Appliance-Hongyu Mao
Made by Hongyu Mao
Made by Hongyu Mao
I test my first code for blink a led
Created: December 15th, 2021
// name the pins
int ledPin = D6;
// create a variable to store the
// current brightness of the LED
int ledValue = 0;
void setup()
{
//Register our Particle function to allow
// Control of the LED
Particle.function("led", ledControl);
// Make the variable 'ledValue' available through
// the Particle cloud as 'brightness'
Particle.variable("brightness", ledValue);
// Set up pin for output
pinMode(ledPin, OUTPUT);
}
void loop()
{
// Nothing to do here
}
int ledControl(String command)
{
// Convert the passed variable to an integer
ledValue = command.toInt();
// Check it is a valid number
if( ledValue > 255 ) return -1;
if( ledValue < 0 ) return -1;
// Use PWM to set the brightness
// of the LED
analogWrite(ledPin, ledValue);
// Return 1 to say completed successfully
return 1;
}
Click to Expand
// variables
int ledPin = D2;
// make it run once //
void setup() {
pinMode(ledPin,OUTPUT); //definte ledPin is output use pinMode //
}
void loop() {
digitalWrite(ledPin,HIGH);
delay(100);
digitalWrite(ledPin,LOW);
delay(100);
digitalWrite(ledPin,HIGH);
delay(100);
digitalWrite(ledPin,LOW);
delay(100);
digitalWrite(ledPin,HIGH);
delay(100);
digitalWrite(ledPin,LOW);
delay(3000);
}
Click to Expand