Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: charlieplexing 72 LED's. Need help with code on: August 11, 2008, 11:51:11 pm
Might be a dumb question but when i use this code (the one from the post above) arduino says "n was not declared in this scope"
I've been studying this option and I finally understand a little more, however I cant make it work.
Best
nico
2  Forum 2005-2010 (read only) / Syntax & Programs / charlieplexing 72 LED's. Need help with code on: July 14, 2008, 12:17:03 pm
Hello
My apologies, I'm a hard working newbie so please excuse my english:

I want to create an array of 72 led's placed horizontally. When I press a switch, the first LED goes on, then the second and so on, in an array.

I am charlieplexing with digital pins 0 to 9.

Below is the code I made (based on knight rider 01 example) using only three pins.  (5, 6, 7)
and a schematics here: www.nicoykatiushka.org/arduino/schematics/72leds.jpg

My problem is that if I keep using this code, I'll have a long and nasty code.

Any suggestions on how to clean or make a nicer code?


thanks

nico


int pin5 = 5;
int pin6 = 6;
int pin7 = 7;
int timer = 500;

void setup(){

  pinMode(pin5, OUTPUT);
  pinMode(pin6, OUTPUT);
  pinMode(pin7, OUTPUT);
}

void loop() {
   pinMode(pin7, INPUT);
   digitalWrite(pin5, HIGH);
   digitalWrite(pin6, LOW);
   delay(timer);

   digitalWrite(pin6, HIGH);
   digitalWrite(pin5, LOW);
   delay(timer);

   pinMode(pin5, INPUT);
   pinMode(pin7, OUTPUT);

   digitalWrite(pin6, HIGH);
   digitalWrite(pin7, LOW);
   delay(timer);

   digitalWrite(pin7, HIGH);
   digitalWrite(pin6, LOW);
   delay(timer);

   pinMode(pin6, INPUT);
   pinMode(pin5, OUTPUT);

   digitalWrite(pin5, HIGH);
   digitalWrite(pin7, LOW);
   delay(timer);

   digitalWrite(pin7, HIGH);
   digitalWrite(pin5, LOW);
   delay(timer);

   setup();
}

3  Forum 2005-2010 (read only) / Troubleshooting / Re: problems running duinoStamp on: October 02, 2008, 03:44:58 pm
I did and they've been very helpful (fundamental logic). I will post the solution to this as soon as I get it.
4  Forum 2005-2010 (read only) / Troubleshooting / problems running duinoStamp on: September 28, 2008, 07:20:01 pm
Hi
I've been trying to run a duinoStamp with no luck.

After it dod not work,

First thing I did was to try the atmega 168 from the duinoStamp on my old NG board (which had previously a atmega smiley-cool, but it does not work. When atmega 168 is connected, pin 13 turns on and off so it is pre programmed.

Second thing was to try the Atmega 8 in the new duinoStamp board, with no luck again.

I changed the baud rate to 19200 and did all the troubleshooting there is on the arduino.cc site, always with no luck.

hope someone can help me.

thanks
5  Forum 2005-2010 (read only) / Workshops / Re: Arduino a Centro y Sudamerica on: October 23, 2008, 11:44:09 pm
will you come to Chile?
6  Forum 2005-2010 (read only) / Workshops / Re: Arduino a Centro y Sudamerica y Chile? on: October 01, 2008, 09:28:08 am
I know this forum is old, but did the workshop in Latin America happened?
thanks
7  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Can you run an LED with analog pins? on: August 16, 2008, 04:45:06 pm

I suspect tho, that manually wiring 306 leds for charliplexing is gonna be quite a pain in the ass.
I would have rather multiplexed them using shift registers and preassembled 8x8 led matrices.
I've a friend who actually manually built a 16x16 led array and I can tell that after placing and soldering 200 of those, he wasn't that excited about the project anymore.
But if you still do it, that would be cool, I fully support you![/quote]
Quote
I suspect tho, that manually wiring 306 leds for charliplexing is gonna be quite a pain in the ass.
I would have rather multiplexed them using shift registers and preassembled 8x8 led matrices.
I've a friend who actually manually built a 16x16 led array and I can tell that after placing and soldering 200 of those, he wasn't that excited about the project anymore.
But if you still do it, that would be cool, I fully support you!

Thanks for the advice. I cannot really use 8x8 because my LED's are placed in a horizontal line. What I will be using is 1/4 inch adhesive conductive http://www.stewmac.com/shop/Electronics,_pickups/Supplies:_Shielding/Conductive_Copper_Tape.html copper tape which I already bought and works great. I haven't got yet the best idea to join the copper with the LED's, which will be a big pain in the ass but I dont really care spending time doing it. I can't solder (and dont want to) because I am working on top of a photo and I dont want to burn it. I've been thinking about using a solder pen or some conductive glue. Any suggestions? I might leave the wiring exposed so I want it to look nice. thishttp://www.flickr.com/photos/62145351@N00/2768386897/sizes/o/ is a photo of the beginning of the schematics, for anyone interested.

8  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Can you run an LED with analog pins? on: August 13, 2008, 10:52:46 pm
I got a new chip and finally made my code work. It is very simple and I can charlieplex up to 306 LED's. I only have a main problem, which is memory space to store the pinArrays (see code below).

PROGMEM sounds like an option, but I haven't been able to make it work, and the other option would be an algorithm... Any suggestions

This is the code. To make it simpler, in this code I only use 4 pins (pin1-4). If you want to use all the pins (pin 1 to pin 19) then both pinArrays are huge and wont fit in my arduino. Any ideas on how to bring this to PROGMEM (yes, I read many times the PROGMEM page on arduino.cc) or to create an algorithm?)

this is the code


int pinArrayh[] = {02,03,04,01,03,04,01,02,04,01,02,03};   //pins high
 int pinArrayl[] = {01,01,01,02,02,02,03,03,03,04,04,04};  //pins low  
int count = 0;                                              
int timer = 300;                          
 
void setup(){  
}  
                                              
void loop() {
                                          
   for (count=0;count<12;count++) {                        
   pinMode(pinArrayh[count], OUTPUT);
   pinMode(pinArrayl[count], OUTPUT);                        
   digitalWrite(pinArrayh[count],HIGH);
   digitalWrite(pinArrayl[count],LOW);
   delay(timer);                                          
   pinMode(pinArrayh[count], INPUT);
  pinMode(pinArrayl[count], INPUT);
   delay(timer);
   }
}
9  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Can you run an LED with analog pins? on: August 11, 2008, 10:38:29 pm
Quote
Quote
Have you tested a simple sketch that just flashes leds, something like this:

Code:
int pinArray[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};  
int count = 0;                                              
                          
 
void setup(){  
}  
                                              
void loop() {
                                          
   for (count=5;count<17;count++) {                        
   pinMode(pinArray[count], OUTPUT);                        
   digitalWrite(pinArray[count],HIGH);
   delay(500);                                          
   digitalWrite(pinArray[count],LOW);
   delay(500);  
   pinMode(pinArray[count], INPUT);
   delay(500);
  }
}

If that works as expected , it may narrow down the things that could be going wrong

It didn't work. I changed your "for" statement so it goes through all the pins: for (count=0;count<17;count++), and it works fine on all pins from 0 to 13 but it will not work for the analog pins.

Is my arduino (Arduino NG, Atmega8) not working right? I doubt it. Because when I use port registers, it works all fine.

I will really appreciate if someone could try on their own arduino this simple task.

10  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Can you run an LED with analog pins? on: August 11, 2008, 02:15:41 pm
I've been doing that since last night, I've checked all the wiring (actually I'm just using two led's for testing purposes. One led is connected to pin 2 (which is HIGH) and one to pin 8 (LOW) and one to analog pin 2 (or pin 16) (LOW) and pin 2 won't work. I've changed the pins, the wires, the led's, the breadboard, everything...
 
By the way, I'm using an atmega8 on a Arduino NG.
 
Logically it shoud work, but it doesnt. I've been doing it for long enough so it can't be a wiring problem.
And if I state for example that an analog pin 2 is HIGH/OUTPUT with port register (PORTC = B00000100, DDRC = B00000100) and use another pin as ground,  it will work no problem, but if I make a for statement where my pinArray is int pinArray ={14, 15, 16, 17, 18, 19}, it will not work. However if my pinArray is pinArray = {8, 9, 10, 11, 12}, it will work with no problem.

My for statement looks like this:

     for (count=0;count<6;count++) {                        
   pinMode(pinArray[count], OUTPUT);                      
   delay(timer2);                                          
   pinMode(pinArray[count], OUTPUT);
   delay(timer2);
   pinMode(pinArray[count], INPUT);
   delay(timer2);
  }

and it works fine (It's a copy from Knight rider example) with pins 8-13, not with analog pins 0-5

strange


11  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Can you run an LED with analog pins? on: August 11, 2008, 01:47:27 pm
Quote
You literally tried:

PORTC = 0;

?

I literally did PORTC = 0;


12  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Can you run an LED with analog pins? on: August 11, 2008, 11:36:58 am
Quote
I guess you could try putting

PORTC = 0;

in your setup() function and see if that fixes the problem.  

I tried that already, but you have to set the pins to 0 or 1 (example PORTC C= B111111111; and DDRC; B111111111;
If I do this, I can't determine the settings of the pins (HIGH or LOW, INPUT or OUTPUT) on my for statement, as I did with pins 8-13. they just stay HIGH.

Is there any statement that would look like this?:

analogPin 0-5 = digitalWrite
13  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Can you run an LED with analog pins? on: August 10, 2008, 09:33:32 pm
Quote
I don't understand what your code is doing, nor do I ever see you set the output values for port C pins (this is the port that has the analog inputs on it).

I'm sorry about that, and sorry for my english too, I'm from Chile. This is my first experience with code and arduino. I'm starting from 0; My code works fine. I made it simpler and hopefully it will be easier to understand. This code is part of a bigger code  to make a Knight Rider with 144 LED's. There MUST be easier ways but I am a beginner and it's hard for me already trying to fix my own code. My only problem right now is that I cannot turn ON the LED's connected to the analog Pins.

Just to put this code in context, I am running 144 leds with charlieplexing. The way I am doing this is setting one pin (ex: digital pin 2) as OUTPUT/HIGH and go through all the others to OUTPUT/LOW.
Then I go to the next pin (ex: digital pin 3) as OUPUT/HIGH and go through all the others, one by one from INPUT to OUTPUT/LOW.

It goes through all the pins turning them on and inmediately off, like the Knight Rider example.

All LED and charlieplexed.

I haven't set the values of the C pins because I don't know how to do this. I tried though. What I dont understand is why my code works from pin 7-13 and it doesnt from analog pin 0-5, if they are suppose to behave as digital too...

this is the code as clean as I could make it:



//I have an array of LED's. All anodes are connected to PIN3 and cathodes are connected to PIN7-19//




int pinArray[] = {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};  //an array from pin 7 to 19, stolen from "knight Rider" example
int count = 0;                                            
int timer = 50;
                          

void setup(){  
}
                                              
void loop() {
                      
   PORTD = B00001000;                  //same as before, pin 3 HIGH and OUTPUT                                          
   DDRD =   B00001000;
  
                                          
   for (count=0;count<13;count++) {    //I got this from the "kinght Rider 3 example. a for statement that turns                    
   pinMode(pinArray[count], OUTPUT);   // from INPUT to OUTPUT every pin from 7 to 19                  
   delay(timer);                                          
   pinMode(pinArray[count], OUTPUT);
   delay(timer);
   pinMode(pinArray[count], INPUT);    // and then turns them INPUT
   delay(timer);                      
  }

  



    
  
}




  
  
  
  
    
    


14  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Can you run an LED with analog pins? on: August 10, 2008, 07:02:41 pm


Quote
Analog inputs 0 - 5 can be used as digital pins 14 - 19.

HI

I need help making my analog pins work. WHen I use port manipulation, it works fine, however when I am not using port manipulation it does not work. What I want to do is a "Knight Rider" using PIN 3 as HIGH and PIN 7-19 as LOW. My code works fine until pin 13 and when it goes to the analog pins, it won't work....

here is the code:
#define x07x B10000000      //D 0-7 , B 8-13,  C 0-5A DDR (i/o)  , PORT (H/L)                
#define x06x B01000000
#define x05x B00100000
#define x04x B00010000
#define x03x B00001000
#define x02x B00000100
#define x01x B00000010
#define x00x B00000001

int pinArray[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};  
int count = 0;                                            
int timer = 50;
int timer2 = 13;                          

void setup(){  
}
                                              
void loop() {
                      
   PORTD = x03x;                                                    
   DDRD =  x03x;  
  
                                          
   for (count=5;count<17;count++) {                      
   pinMode(pinArray[count], OUTPUT);                      
   delay(timer2);                                          
   pinMode(pinArray[count], OUTPUT);
   delay(timer2);
   pinMode(pinArray[count], INPUT);
   delay(timer2);
  }


15  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Can you run an LED with analog pins? on: August 08, 2008, 01:14:01 pm
Thank you. I am using Port Manipulation to run the LED's. I need to make a very simple array where one LED turns on and the previous turns off, then the next one turns on and the previous off (something like a shooting star or a knight rider). With Port Manipulation I've been able to clean my code however I have never tested it with more than 20 LED's.

I had no idea I would have problems with the duty cycle (I don't know what a duty cycle is and can't find a good explananation on the arduino.cc site) Sorry I'm really starting with arduino and code!!!

Today I received this code which might be helpful. It's a little hard to understand but as soon as I make it work I will post my results. It seems that with this code I won't need to charlieplex and I would be able to run all LED's in two pins. IS THIS RIGHT?

unsigned char cathodes[72] = {1,2,0,2,3,4,5,6, ...};
unsigned char anodes[72] =   {0,0,0,0,0,0,0,0,0, 1,1,1,1,1,1,...};

void light_cp_led(unsigned char N)
{
  static unsigned char last_n;
  pinMode(cathodes[last_n], INPUT);  // turn off previous LED
  pinMode(anodes[last_n], INPUT);  // on both ends
  pinMode(cathodes[n], OUTPUT);  // turn on new LED cathode
  digitalWrite(cathodes[n], LOW);
  pinMode(anodes[n], OUTPUT);  // turn on new LED annode
  digitalWrite(anodes[n], HIGH);
}
 

Pages: [1] 2