Are My Kids Home Yet? Code
int sara = A0;
int raha = A1;
int saraLED = D0;
int rahaLED = D1;
int button = D4;
int saraState = 0;
int rahaState = 0;
int threshold = 3000;
void setup()
{
pinMode(saraLED, OUTPUT);
pinMode(sara, INPUT);
pinMode(rahaLED, OUTPUT);
pinMode(raha, INPUT);
pinMode (button, INPUT_PULLUP);
Particle.variable( "sara", &saraState, INT );
Particle.variable( "raha", &rahaState, INT );
Serial.begin (9600);
}
void loop()
{
saraState = analogRead(sara);
rahaState = analogRead(raha);
int buttonState = digitalRead (button);
if (buttonState == LOW) {
systemOn ();
}
else {
systemOff ();
}
}
void LEDupdates (bool state1, bool state2){
digitalWrite (saraLED, state1);
digitalWrite (rahaLED, state2);
}
void systemOn () {
if (saraState > threshold) {
if (rahaState > threshold) {
LEDupdates (true, true);
}
else {
LEDupdates (true, false);
}
}
else if (saraState < threshold) {
if (rahaState > threshold){
LEDupdates (false, true);
}
else {
LEDupdates (false, false);
}
}
}
void systemOff (){
LEDupdates (false, false);
}
Rebecca Radparvar
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. .