Show Posts
Pages: [1] 2
1  Using Arduino / General Electronics / Re: Struggling to understand the basics of a 7 segment display common anode on: February 09, 2013, 11:39:25 pm
You were right. I was blinking the leds confusing myself. To confirm I turned all leds on by letting it remain on digitalWrite(2, LOW). Also tried your experiment and you were double right. So when I set the Write to LOW does that send power in that direction?
2  Using Arduino / General Electronics / Struggling to understand the basics of a 7 segment display common anode on: February 09, 2013, 10:55:22 pm
I have built something similar to this.



My LED works fine. The problem is I do not understand how the circuit works. The anode side, display pins 3 and 8, receive power. Lets say for now I have pin 2 of the display going to pin 2 on the arduino board.

Now in my mind the pin 2 on the arduino board should complete/ground the circuit. However the program sketch uses pinmode(2, OUTPUT) and I use digitalWrite(2, HIGH) to turn on that specific led.

How does the cathode side of this CA 7-seg display work?
3  Using Arduino / LEDs and Multiplexing / Re: Electronics 101, Ohm's law, Arduino and blue leds! Beginner here... on: February 02, 2013, 08:15:06 pm
Ok newb mistake. I had been making my anode/cathode judgement based on what direction the diode parts faced assuming all LEDS were built the same. Turns out my reds and blues are opposite. I should have been paying attention to which leg was longest. Thanks for your time.
4  Using Arduino / LEDs and Multiplexing / Re: Electronics 101, Ohm's law, Arduino and blue leds! Beginner here... on: February 02, 2013, 08:02:11 pm
I do believe so. Switching it around seems to do nothing but all my other LEDS work in the direction I have this blue one.
5  Using Arduino / LEDs and Multiplexing / Re: Electronics 101, Ohm's law, Arduino and blue leds! Beginner here... on: February 02, 2013, 04:09:14 pm
Sure. I am just using the basic blink example program.

Code:
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

I checked the led polarity. Looks correct. I can send a pic later if needed.
6  Using Arduino / LEDs and Multiplexing / Re: Electronics 101, Ohm's law, Arduino and blue leds! Beginner here... on: February 02, 2013, 03:58:49 pm
Is it erroneous for me to use a 100ohm resistor? Any troubleshooting tips on why I could not blink this blue LED?
7  Using Arduino / LEDs and Multiplexing / Electronics 101, Ohm's law, Arduino and blue leds! Beginner here... on: February 02, 2013, 03:37:30 pm
Hi everyone,


Apologizes for the very basic question. I am struggling to understand what kind of resistor to use for a specific LED. I have 10 blue LEDS and an arduino uno. The packaging on the led states, "3.0-3.3v @ 20mA". Possibly I am not understanding how to calculate this. I have been studying from this site. I tried to search the forums but I don't know if anyone has dared to ask a question as basic as this...  smiley-lol

I want to blink this blue LED on a digital pin. Is this as simple as (5.0 - 3.3) / 0.02 = r ?


8  Using Arduino / Project Guidance / Re: Cannot blink pins 7 through 5 (NEWBIE) on: January 27, 2013, 10:21:10 pm
Video of the clock.
9  Using Arduino / Project Guidance / Re: Cannot blink pins 7 through 5 (NEWBIE) on: January 27, 2013, 09:35:09 pm
Alright well I have a working clock. In my excitement to get it all working I may have mangled my code a bit. I had to add a crude setup process so you could set the right time. Still it is wonderful that I got it up and running.

Now I can refine it and improve it. Since this is the first real thing I've made with Arduino it has spiked a load of questions regarding electronics. Some of resistors I used were guess work. I'll probably post some followup questions in the electronics forum.

Below is what I have so far in my code.
Code:
//#define NUM_ITEMS(arg) ((unsigned int) (sizeof (arg) / sizeof (arg [0])))

int const MINUTES[] = {13, 12, 11, 10, 9, 8};
int const HOURS[] = {7, 6, 5, 4};
int hours = 1;
int minute = 0;
int setup_time = 10000;

void setup() {               
  for(int led = 4; led < 14; led++){
    pinMode(led, OUTPUT);
  }
  //Serial.begin(9600);
  pinMode(3, INPUT);
}

//int array_size(int const a[]) {
//  return (sizeof(a)/sizeof(int)); 
//}

void blink_binary_number(int number, int const pin_array[], int a_size){
  for(int led = 0; led < a_size; led++){
    if (bitRead(number, led) == 1){
      digitalWrite(pin_array[led], HIGH);
    } else {
     digitalWrite(pin_array[led], LOW);
    }
  }
}

void loop() {
  while (setup_time > 0) {
    if (digitalRead(3) == HIGH) {
//      Serial.print("Minute: ");
//      Serial.println(minute);
//      Serial.print("Hour: ");
//      Serial.println(hours);
//      Serial.println("------");       
      blink_binary_number(hours, HOURS, 4);
      blink_binary_number(minute, MINUTES, 6);

      //Incriment time   
      minute++;
      if (minute == 60) {
        minute = 0;
        hours++; 
      }
     
      if (hours > 12) {
        hours = 1;
      }
      delay(150);
      setup_time = 10000;
    } else {
     delay(10);
     setup_time = setup_time - 10;
    }
  }
 
 
//  Serial.print("Minute: ");
//  Serial.println(minute);
//  Serial.print("Hour: ");
//  Serial.println(hours);
//  Serial.println("------");   
 
  blink_binary_number(hours, HOURS, 4);
  blink_binary_number(minute, MINUTES, 6);

 //Incriment time   
  minute++;
  if (minute == 60) {
    minute = 0;
    hours++; 
  }
 
  if (hours > 12) {
    hours = 1;
  }
  delay(60000);
}



Uploading a video now.
10  Using Arduino / Project Guidance / Re: Cannot blink pins 7 through 5 (NEWBIE) on: January 27, 2013, 09:15:29 pm
That makes perfect sense. It has been a very long time since I've coded in c++ but some of this is coming back. Do you think the way I have it now is acceptable?
11  Using Arduino / Project Guidance / Re: Cannot blink pins 7 through 5 (NEWBIE) on: January 27, 2013, 02:37:56 pm
I've made some wonderful progress. I have all my pins blinking and my binary counting for the hour leds and minute leds are working great. I've cleaned up my blink_to_binary function a bit so that it only needs to be called once per array of pins.

Code:
#define NUM_ITEMS(arg) ((unsigned int) (sizeof (arg) / sizeof (arg [0])))

int const MINUTES[] = {13, 12, 11, 10, 9, 8};
int const HOURS[] = {7, 6, 5, 4};
int const delayms = 500;
int hours = 1;

void setup() {               
  for(int led = 4; led < 14; led++){
    pinMode(led, OUTPUT);
  }
  Serial.begin(9600);
}

int array_size(int const a[]) {
  return (sizeof(a)/sizeof(int)); 
}

void blink_binary_number(int number, int const pin_array[], int a_size){
  for(int led = 0; led < a_size; led++){
    if (bitRead(number, led) == 1){
      digitalWrite(pin_array[led], HIGH);
    } else {
     digitalWrite(pin_array[led], LOW);
    }
  }
}

void loop() {
  for(int x = 0; x < 60; x++){
   
    Serial.print("Minute: ");
    Serial.println(x);
    Serial.print("Hour: ");
    Serial.println(hours);
    Serial.println("------");   
   
    blink_binary_number(hours, HOURS, 4);
    blink_binary_number(x, MINUTES, 6);
   
    if (x == 59) {
      hours++; 
    }
   
    if (hours > 12) {
      hours = 0;
    }
    delay(delayms);
  }
}

I did run into a snag with catching array size. I wanted my bit_to_binary function to be able to handle any array size. I also don't want it trying to access the next element in an array if it doesn't exist so I only want to count up to the array size.

I made two array_size functions to accomplish this. NUM_ITEMS and array_size. If I run these inside of my blink_binary_number the array size is always one.

I want to do something like this

Code:
void blink_binary_number(int number, int const pin_array[]){
  a_size = array_size(pin_array);

  for(int led = 0; led < a_size; led++){
    if (bitRead(number, led) == 1){
      digitalWrite(pin_array[led], HIGH);
    } else {
     digitalWrite(pin_array[led], LOW);
    }
  }
}
void loop() {
  blink_binary_number(number, HOURS_ARRAY);
}

However every time I run this method inside of the blink_binary_number HOURS_ARRAY always returns 1. If I run it from within void loop it correctly returns a length of 4. For now I just pass the array size into the function but it would be nice if the function could just handle this for me.

I know this is probably due to a lack of understanding in what is going with hour the array is referenced. Can someone help me understand this?

I'll send pictures and perhaps a video of what I have so far in a bit.
12  Using Arduino / Project Guidance / Re: Cannot blink pins 7 through 5 (NEWBIE) on: January 26, 2013, 11:55:37 pm
I got all 3 pin, 5-7, to blink individually. I think I made some wiring mistakes. Apparently some of my LEDS are 3.0-3.2V and they didn't work on the digital pins. I'll continue in the morning with more information. Thanks guys.
13  Using Arduino / Project Guidance / Re: Cannot blink pins 7 through 5 (NEWBIE) on: January 26, 2013, 10:43:38 pm
Quote from: HazardsMind
...
Quote from: PeterH
...

I am troubleshooting this now. I got pins 5-7 blink after disconnecting everything. I'll keep you guys posted. Thanks again for the help.
14  Using Arduino / Project Guidance / Re: Cannot blink pins 7 through 5 (NEWBIE) on: January 26, 2013, 01:10:50 pm
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.
15  Using Arduino / Project Guidance / Re: Cannot blink pins 7 through 5 (NEWBIE) on: January 26, 2013, 01:05:16 pm
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.
Pages: [1] 2