Isn’t this exactly how you write a HIGH signal on pin 8? How can this
destroy the chip? And there is no reason to expect that these two
statements are in the same function, or even the same compilation unit.
For that matter, there is no guarantee that the first parameter is a ctce
(compile-time constant expression). For example, I might have three
identical devices, for the sake of this example, on pins 8,9 and 10, so
how would it even be possible to detect
in myprog.ino:
void setup()
{
for(byte i = 8; i <= 10; ++i)
pinMode(i, OUTPUT);
}
in device.cpp
void device::activate(byte pin)
{
digitalWrite(pin, HIGH):
}
The desired circuit is to set pins 4, 5, and 6 to INPUT_PULLUP, with a
pushbutton connected to GND, and have the following code (note that all
aspects of these examples are horrible examples of coding, but I would
write would be elegant and maintainable, but would make it even more
ridiculously impossible to do the detection. For example, I might start
with
struct {
byte signalpin;
byte activatorpin:
} pinmap[ ] = {
{ 4, 8 },
{ 5, 9 },
{ 6,10}
};
and all those numeric values in the above table would be named const byte
values. How I would use this is left as an Exercise For The Reader).
in myprog.ino:
void loop()
{
for(byte i = 4; i <= 6; ++i)
{
if(digitalRead(i) == LOW)
device::activate(i + 4);
else
device::deactivate(i + 4);
}
[Yes, I know I didn’t debounce the switch. Assume the switch is magically
debounced. The purpose of this example is to illustrate the absurdity of
checking for the problem. Which I don’t believe is a problem, unless
there is something weird about pin 8 that is not well-documented].
joe
> --
> You received this message because you are subscribed to the Google Groups
> "Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
developers+...@arduino.cc.
>