Skills Dev V: Working with Networking
Made by Alp Erbug, bmkaufma, Tyler Howe and pgomezte
Made by Alp Erbug, bmkaufma, Tyler Howe and pgomezte
This projects connects 2 Particle Argons. Using one of the Argons, we are able to control components connected to the other Argon.
Created: December 13th, 2022
// We will be using D2 to control our LED
int ledPin = D2;
// Our button wired to D0
int buttonPin = D3;
bool doButton = false;
void setup()
{
pinMode( buttonPin , INPUT_PULLUP); // sets pin as input
// We also want to use the LED
pinMode( ledPin , OUTPUT ); // sets pin as output
Particle.function("spinFan", spinFan);
Particle.subscribe( "buttonPressed", handleButtonPressed );
}
void loop()
{
// find out if the button is pushed
// or not by reading from it.
int buttonState = digitalRead( buttonPin );
if( buttonState == LOW )
{
// turn the LED On
digitalWrite( ledPin, HIGH);
Particle.publish("buttonPressed2");
delay(1000);
}else{
// otherwise
// turn the LED Off
digitalWrite( ledPin, LOW);
}
if( doButton == true ){
digitalWrite( ledPin, HIGH);
delay(1000);
doButton = false;
}
}
void handleButtonPressed( const char *event, const char *data)
{
doButton = true;
}
int spinFan(String command)
{
digitalWrite( ledPin, HIGH);
int runTime = command.toInt() * 1000;
delay(runTime);;
return 1;
}
Click to Expand
int ledPin = D3;
int buttonPin = D5;
bool doButton = false;
void setup()
{
pinMode( buttonPin , INPUT_PULLUP);
pinMode( ledPin , OUTPUT ); // sets pin as output
Particle.subscribe( "buttonPressed2", handleButtonPressed );
}
void loop()
{
// find out if the button is pushed
// or not by reading from it.
int buttonState = digitalRead( buttonPin );
if( buttonState == LOW )
{
// turn the LED On
digitalWrite( ledPin, HIGH);
Particle.publish("buttonPressed");
delay(1000);
}else{
// otherwise
// turn the LED Off
digitalWrite( ledPin, LOW);
}
if( doButton == true ){
digitalWrite( ledPin, HIGH);
delay(1000);
doButton = false;
}
}
void handleButtonPressed( const char *event, const char *data)
{
doButton = true;
}
Click to Expand