user68473: I have the following code to turn on or off led. I would like to modify the function to pass the pin as well. what should X be substituted with?
#define BIN_LED 2
#define PIN_LED 3

void led(uint8_t x, bool on) {
 digitalWrite(x, on ? LOW : HIGH);
}

void setup() {}

void loop() {
 led(BIN_LED, true);
 delay(1000);
 led(BIN_LED, false);
 delay(1000);
}


user313: You've done it. All that's left is to specify a data-type 'X' in the function declaration, just as you've already done for 'on'. 'uint8_t' would be a reasonable choice.

68473: <p>I have the following code to turn on or off led. I would like to modify the function to pass the pin as well. what should X be substituted with?</p>
<pre><code>#define BIN_LED 2
#define PIN_LED 3

void led(uint8_t x, bool on) {
 digitalWrite(x, on ? LOW : HIGH);
}

void setup() {}

void loop() {
 led(BIN_LED, true);
 delay(1000);
 led(BIN_LED, false);
 delay(1000);
}
</code></pre>
 313: <p>You've done it. All that's left is to specify a data-type 'X' in the function declaration, just as you've already done for 'on'. 'uint8_t' would be a reasonable choice.</p>
