Trying to learn a few things and killed a nano by putting 5v on pins 6 and 7 simultaneously (using a wire). They were not set as LOW outputs. Why did this happen?
int pin6 = 6; //pin #
int pin7 = 7; //pin #
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
if (digitalRead (pin6 == LOW && pin7 == LOW)) {
slowblink();
} else {
fastblink();
}
}
void slowblink ()
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}
void fastblink ()
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(100);
}
I used this sketch to verify Inputting on 6 and 7.
Taking a pin HIGH should not result a board catastrophe.
digitalReads cannot be combined as your sketch attempts.
const byte Six = 6;
const byte Seven = 7;
byte together;
void setup()
{
Serial.begin(9600);
}
void loop()
{
together = 0;
if (digitalRead(Six) == HIGH)
{
together = together + 6;
}
if (digitalRead(Seven) == HIGH)
{
together = together + 7;
}
Serial.println(together);
delay(500);
}
PerryBebbington:
He means is that the correct way to read 2 different input pins and combine the result, and if not, what is the correct way? Do some research.
Ahh, ok. I will look in to that. Thanks both of you.
runaway_pancake:
I used this sketch to verify Inputting on 6 and 7.
Taking a pin HIGH should not result a board catastrophe.
I know, that is why I'm so confused. I just ran a wire from the 5v pin to D6 and D7 and it killed it. I don't know why. It gets warm too. I have to admit I did it twice. If I do it again, that means I am insane, right? I don't want to be insane.
Just to make things clear, since the previous replies on this point seem very vague and confusing to me:
ElHefe:
if (digitalRead (pin6 == LOW && pin7 == LOW)) {
In this code, you're comparing the value of the pin6 and pin7 variables to the value of LOW. LOW is usually defined as 0 (though you shouldn't assume that), so pin6 == LOW && pin7 == LOW will always evaluate to false. Therefore, this code is the equivalent of:
if (digitalRead (false)) {
which is the equivalent of:
if (digitalRead (0)) {
So you're testing the state of pin 0, definitely not what you intended.
If your intention was to test whether both pin 6 and pin 7 are LOW, the correct code would look like this:
if (digitalRead(pin6) == LOW && digitalRead(pin7) == LOW)) {