PDA

View Full Version : how to control Arduino pins Simultaneously?



brian25
08-12-2013, 11:19 PM
using functions how to compare the pins of arduino with the buffer(pointer) to an array or string? if the incoming data is matched to the user input pin it will execute the program in function example is arduino pin 2,3,4,5 High.

jwatte
08-13-2013, 12:12 AM
What's wrong with a simple if() statement?

Where would the string come from?

brian25
08-13-2013, 02:50 AM
how to pass the conditional statement in if() statement in array of arduino pins?

tnx

int PIN[] = {3,4,5};
int LedCnt = 3;


void setup()
{

for(int p=0; p<LedCnt; p++)
{
pinMode(PIN[p], OUTPUT); // Set the mode to OUTPUT
}


void loop()
{
LEDON();
}



void LEDON()
{


if (strncmp (smsbuffer, LED, 3) == 0)
{
Serial.println(smsbuffer);
for(int p=0; p<LedCnt; p++)
{

digitalWrite(PIN[p], HIGH);
delay(1000);
Serial.println("ALL PINS ON");
}
}

jwatte
08-13-2013, 11:47 AM
I see -- you have an array of pin IDs, and you want to test whether all pins in that array are high.
This needs a loop.


bool AreAllPinsOn(int const *pins, int count) {
for (int ix = 0; ix != count; ++ix) {
if (digitalRead(pins[ix]) != HIGH) {
return false;
}
}
return true;
}

...
int pins[] = { 5, 9, 13 };

if (AreAllPinsOn(pins, 3)) {
...
}