Pages: [1] 2   Go Down
Author Topic: Cannot blink pins 7 through 5 (NEWBIE)  (Read 1493 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Everyone,

I am trying to make a binary clock to help facilitate my learning of electronics and of the Arduino.

Give my code here, I am unable to blink my HOUR pins.
Code:
int const MINUTES[] = {13, 12, 11, 10, 9, 8};
int const HOURS[] = {7, 6, 5};
int const delayms = 1000;
int const up_to = 60;

void setup() {               
  // initialize digital pins as outputs.
  for(int led = 5; led < 14; led++){
    pinMode(led, OUTPUT);
  }
  Serial.begin(9600);
}


void blink_binary_number(int number, int const pin_array[], boolean vol=HIGH){
  for(int led = 0; led < number; led++){
    if (bitRead(number, led) == 1){
      digitalWrite(pin_array[led], vol); //Here we use our PINS array to decide which LED to blink. Since I wanted 13 to be bit 0, 12 bit 1, etc...
    }
  }
}

void loop() {
  int hours = 1;
 for(int x = 0; x < up_to; x++){
   
   Serial.println(x);
   //Serial.println(hours);
   
   //blink_binary_number(hours, HOURS);
   blink_binary_number(x, MINUTES);
   delay(delayms);
   //blink_binary_number(hours, HOURS, LOW);
   blink_binary_number(x, MINUTES, LOW);
   
   if (hours < 13) {
     hours++;
   } else {
    hours = 0;
   }
 }
}

Here is a picture of my board. Pins 5,6,7 being the back 3 pins. For now I just wired up 3 but I'll need 4 to at least count to 12 obviously. I hadn't proceeded that far since I can't get any of these 3 to blink.

Picture
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Even if I load the example file Blink.ino I cannot blink those pins
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 98
Posts: 3575
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try analogWrite, you might have burned out your arduino.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12631
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't looked into the logic you're using to control the writes, but at first glance it's complex enough that I'm not certain whether you are actually doing a digitalWrite(HIGH) on the relevant pins. Write a sketch that does nothing but set the mode to output and set the pins HIGH, disconnect all the external wiring and just connect one LED with a current limiting resistor to each output pin in turn, with the other leg of the LED grounded.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try analogWrite, you might have burned out your arduino.

I'll give that a shot. All the other pins continue to blink fine.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't looked into the logic you're using to control the writes, but at first glance it's complex enough that I'm not certain whether you are actually doing a digitalWrite(HIGH) on the relevant pins. Write a sketch that does nothing but set the mode to output and set the pins HIGH, disconnect all the external wiring and just connect one LED with a current limiting resistor to each output pin in turn, with the other leg of the LED grounded.

All the pins work except for pins 5 through 7. It should do a digitalWrite(PIN#, HIGH). Its not that big. It may be easier to read on the github page.

I did try to blink those pins using the example file Blink.ino though I did not disconnect everything so perhaps I will try that.
Logged

Wisconsin
Offline Offline
Edison Member
*
Karma: 4
Posts: 1001
I LOVE THIS STUFF!!!!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Alright, there are numerous problems with your code. 

1) You have absolutely no code driving the Hours pins (5,6,7).  Looks like they are commented out.
 
2) In your loop() you have two different functions.  Although they are both called blink_binary_number, they are overloaded.

3) do not assign a variable in your parameters list of a method, whether it works or not, its a convention.  You just don't do that.

4) Your digital write is funky,  when you call your method, you are sending a LOW with it.  The problem is, in your blink_binary_number method, it doesn't do anything unless the pin is already HIGH.  So even if you sent the method a HIGH, if the pin wasn't already HIGH, it wouldn't do a single thing. 

Your blink_binary_number method is underdeveloped.  You cannot do what you are trying to do with just four lines of code.

Logged

Accelerate to 88 miles per hour.

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12631
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

All the pins work except for pins 5 through 7. It should do a digitalWrite(PIN#, HIGH). Its not that big. It may be easier to read on the github page.

It's not a question of size. You are assuming that your sketch does what you want. I'm saying don't make that assumption; write a sketch that just turns that output HIGH in the simplest possible way. You don't need github or anything else to write that. Just set the pin mode and set the pin high. Eliminate all the superfluous hardware and just test one specific output with your LED and current limiting resistor. Don't allow any other complexity at all into your test system.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Queens, New York
Offline Offline
Faraday Member
**
Karma: 98
Posts: 3575
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What is "boolean vol=HIGH" doing?
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try analogWrite, you might have burned out your arduino.

I plan on trying this tonight but it seems weird to me that I would need to do this. Aren't pins 5-7 digital?

What is "boolean vol=HIGH" doing?

Perhaps I am not doing this in the most appropriate way. To blink my leds I simply copied the methods demonstrated in the blink tutorial file, blink.ino. This can be loaded from within the Arduino IDE from File -> Examples -> Basics.

The method used is digitalwrite. My function just assumes a default variable of const HIGH.

In retrospect I can see how it degrades the readability of the program. I don't gain anything by having the default value here. I will probably remove this. Actually in thinking about it and based on some other points here I'll rewrite blink_binary_number to address all leds. I will turn off LEDS that should be off and turn on leds that should be on. In this way I can call the function once per loop rather than twice(Once to turn off and again to turn off).

Does that make sense?

Back to the problem discovered in the OP I can use the blink sketch to blink pins 5 through 7. This arduino board is brand new. Is it possible I did something wrong?
« Last Edit: January 26, 2013, 12:42:05 pm by crosson » Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 98
Posts: 3575
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pins 5 & 6 are PWM so they will work with analogWrite. 7 is digital. I found out that I burnt out my Nano, and my pins would only go high when I did analogWrite(pin, 255) and not digitalWrite(pin,HIGH).
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Alright, there are numerous problems with your code.  
2) In your loop() you have two different functions.  Although they are both called blink_binary_number, they are overloaded.
I don't follow. My blink_binary_number is defined once. It is not overloaded. I do call the function several times however.

3) do not assign a variable in your parameters list of a method, whether it works or not, its a convention.  You just don't do that.

So defaults, by convention, are generally frowned on? I did try to search for Arduino sketch conventions but didn't pull anything related to it. I think in this case I am going to remove the default assignment since it does not add to the program in anyway and takes away the readability. Though based on your comment it is not clear why the Arduino community adopts avoiding defaults by convention.

These points posted do not address why pins 5 through 7 won't blink.

4) Your digital write is funky,  when you call your method, you are sending a LOW with it.  The problem is, in your blink_binary_number method, it doesn't do anything unless the pin is already HIGH.  So even if you sent the method a HIGH, if the pin wasn't already HIGH, it wouldn't do a single thing.  

I don't follow. The method as is currently does not behave this way. Keep in mind I have spent all of about 2 hours with Arduino sketching so it is possible I am not understanding it but I don't think that method is behaving as your describe above.

For my first hello world sketch I used this method to create a binary counter that would count up to 31(I only had 5 pins at the time). Unfortunately I did not use pins 5-7 so I don't know if I would have the same problem or not.

Anyhow the blink_binary_number worked as intended. I got some fantastic feedback from Nick Gammon when setting it up. Here is a video of the counter in action. Here is the actual sketch itself. So we know the function is working to an extent.

Your blink_binary_number method is underdeveloped.

Yes I think you are right. Is it wise to send a LOW to pins that are already turned off? Is there any harm in this? If not I could send LOW to each PIN who represents the binary 0 in the binary array and I could send HIGH to each pin that represents the binary 1. When the number changes the function will just turn off the pins that need to be off and turn on the pins that need to be on. I would only need to call the function once per loop.

 You cannot do what you are trying to do with just four lines of code.

What am I trying to do with just 4 lines of code? Do tell. smiley
« Last Edit: January 26, 2013, 01:11:39 pm by crosson » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pins 5 & 6 are PWM so they will work with analogWrite. 7 is digital. I found out that I burnt out my Nano, and my pins would only go high when I did analogWrite(pin, 255) and not digitalWrite(pin,HIGH).

Ok I will definitely try this tonight. I am beginning to wonder if I did this. Fortunately I do have another uno I can test on as well. Thanks HazardsMind I'll keep you posted.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are assuming that your sketch does what you want.  I'm saying don't make that assumption;
Well presently I am not sure what is going on. Hence the post here. I suspected something wrong with my sketch.

write a sketch that just turns that output HIGH in the simplest possible way.

Right. Which is why I tried using the blink example sketch. You may have missed this but the second post mentions that I tried this.

You don't need github or anything else to write that.

I don't follow. Github isn't used for writing sketches.

Eliminate all the superfluous hardware and just test one specific output with your LED and current limiting resistor. Don't allow any other complexity at all into your test system.

This is a good point. I plan on trying this and Hazards notes tonight when I get a chance. Thanks for the feedback Peter.
Logged

Wisconsin
Offline Offline
Edison Member
*
Karma: 4
Posts: 1001
I LOVE THIS STUFF!!!!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay well to really help you, because your code is atrocious and we still haven't gotten an update, tell us what your project is.

Are you just trying to make a binary clock?  Because there is a plethora of code for that out there already.
Logged

Accelerate to 88 miles per hour.

Pages: [1] 2   Go Up
Jump to: