Show Posts
Pages: 1 2 [3] 4
31  Using Arduino / Project Guidance / Re: Arduino doesn't do what I've written in the code on: March 06, 2013, 06:13:12 pm
I hope so PeterH, I'm looking for an error in the code or something that I've written wrong, I'm sure that there something that I don't see at this moment but sooner or later I'll find out what's the problem. Thanks for your help, in the case that I can't find the error in this week I'll scream for help here  smiley-money
32  Using Arduino / Project Guidance / Re: Arduino goes nuts when doing this... on: March 06, 2013, 10:16:54 am
It could help if you paste here the code you are using.....
33  Using Arduino / Project Guidance / Re: Arduino doesn't do what I've written in the code on: March 05, 2013, 09:12:13 pm
spatula, thanks for your advice, I haven't see it, now it works and exit the switch....case routine, but it seems like the Arduino doesn't read the ledPins state and doesn't save the state of the pins to the EEPROM. It's possible that the digitalRead function doesn't work with pins in ouput mode........or that I need to use another method instead of bitWrite to save the ledPins state in the byte valores........I will read some more manuals and hoping that the digitalRead function works with output pins.
Thanks for your help, another little step ahead.
34  Using Arduino / Project Guidance / Re: Arduino doesn't do what I've written in the code on: March 05, 2013, 08:01:22 pm
Well I'm at this point:

Code:
/*
Using 8 outputs and saving output presets in the EEPROM
 */
#include <Keypad.h> //Inlcude Keypad Library
#include <EEPROM.h>                            //Include EEPROM Library
#include <DigitalToggle.h>       //Include DigitalToggle Library
int ledPins[] = {
  0,1,2,3,4,5,6,7};               //Defining program mode Leds
int bypassled = 11;                           //Defining the bypass Led
int latchPin = 14;       //Defining latchPin from the 74HC595
int clockPin = 15;       //Defining clockPin from the 74HC595
int dataPin = 13;       //Defining dataPin from the 74HC595
const byte filas = 4; // rows of the Keypad
const byte colus = 4; // columns of the Keypad
char teclas[filas][colus] = {       //mapping the Keypad layout
  {
    '1', '2', '3', '4'             }
  ,
  {
    '5', '6', '7', '8'             }
  ,
  {
    '9', '0', 'A', 'B'             }
  ,
  {
    'C', 'D', 'E', 'F'             }
};

// defining the pins that are used for the rows and columns of the Keypad

byte filaPins[filas] = {
  16, 17, 18, 19 };
byte coluPins[colus] = {
  8, 9, 10, 12 };       
Keypad teclado = Keypad( makeKeymap(teclas), filaPins, coluPins, filas, colus );
byte dataOut = 0;
byte valores = B00000000;
int posi = 0;
byte memo0 = B00000000;                   //the bypass value is always the same, so it's not necessary to save it in the EEPROM
byte memo[] = {
  0,5,10,15,20,25,30,35,40,45,50,55,60,65};  // defining the EEPROM adresses

void setup()
{
  for(int index = 0; index <= 8; index++) //defining output pins
  {
    pinMode(ledPins[index], OUTPUT);
  }
  pinMode(bypassled, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  for(int index = 0; index <= 7; index++)
  {
    digitalWrite(ledPins[index], LOW); // shutdown the programming Leds
  }
  digitalWrite(bypassled, HIGH); // lighting the bypass Led
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, memo0); 
  digitalWrite(latchPin, HIGH);
  delay(1000); //wait a second........

}

void loop()
{
  teclado.setDebounceTime(10);
  char key = teclado.getKey();
  switch(key) //the key we select sends a memory content assigned to this key
  {        
  case '1':
    enviamemo(0);                               
    break;
  case '2':
    enviamemo(1);
    break;
  case '3':
    enviamemo(2);
    break;
  case '4':
    enviamemo(3);
    break;
  case '5':
    enviamemo(4);
    break;
  case '6':
    enviamemo(5);
    break;
  case '7':
    enviamemo(6);
    break;
  case '8':
    enviamemo(7);
    break;
  case '9':
    enviamemo(8);
    break;
  case '0':
    enviamemo(9);
    break;
  case 'A':
    enviamemo(10);
    break;
  case 'B':
    enviamemo(11);
    break;
  case 'C':
    enviamemo(12);
    break;
  case 'D':
    enviamemo(13);
    break;
  case 'E':
    modobypass();              //In case we select the 'E' key we set the bypass mode
    break;
  case 'F':
    modoPrograma();            //if we select the 'F' key we are entering in the programming mode
    break;
  }
}   

void modoPrograma()
{
  digitalWrite(bypassled, LOW);
  {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, memo0); 
    digitalWrite(latchPin, HIGH);
    delay(500);
    for (int i = 0; i <= 2; i++)
    {
      for(int index = 0; index <= 7; index++)
      {
        digitalWrite(ledPins[index], HIGH); // we make blink the programming Leds three times, so we know that we are entering programming mode
      }
      delay(500);
      for(int index = 0; index <= 7; index++)
      {
        digitalWrite(ledPins[index], LOW);
      }
      delay(500);
    }
  }
  {
    char key;
    do
    {
     key = teclado.getKey();
      switch(key)
    {              
    case '1': //Now we select which outputs we want to have ON or OFF
      digitalToggle(ledPins[0]);
      break;                 //The programming Leds shows us which Output will be ON or OFF
    case '2': //in the preset, every Led corresponds to an Output.
      digitalToggle(ledPins[1]);
      break; //we use the digitalToggle library to change the state of each Led
    case '3':
      digitalToggle(ledPins[2]);
      break;
    case '4':
      digitalToggle(ledPins[3]);
      break;
    case '5':
      digitalToggle(ledPins[4]);
      break;
    case '6':
      digitalToggle(ledPins[5]);
      break;
    case '7':
      digitalToggle(ledPins[6]);
      break;
    case '8':
      digitalToggle(ledPins[7]);
      break;
    }
  }
while (key != 'E');                                  //If we press the 'E' key we go to the next step
   
}
  posi = 0;                                         //we reset posi
  valores = B00000000;                   //we reset valores
  for(int i=0; i <= 7; i++) //we save every Led state in the byte valores
  {
    bitWrite(valores, posi, digitalRead (ledPins[i]));
    posi = posi + 1;
  }
    guardamemoria(valores); // calling the save function
    {
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, memo0); 
      digitalWrite(latchPin, HIGH);
      delay(500);
      for (int i = 0; i <= 2; i++)
      {
        for(int index = 0; index <= 7; index++)
        {
          digitalWrite(ledPins[index], HIGH); // we make blink the programming Leds three times, so we know that we are exiting programming mode
        }
        delay(500);
        for(int index = 0; index <= 7; index++)
        {
          digitalWrite(ledPins[index], LOW);
        }
        delay(500);
      }
    } 
}
void guardamemoria(byte valores) //function to save the byte valores in the EEPROM, this byte contains the preset information that we have programmed
{
  char key;
  do
  {
  char key = teclado.getKey();         //HERE IS WHERE THE ARDUINO STAYS FOREVER AND IT DOESN'T EXIT, IT DOESN'T MATTER WHICH KEY I PRESS!!!!!
  switch(key) //Now we select in which adress of the EEPROM we want to save the Byte value
  {
  case '1':
    grabamemo(0, valores);             
    break;
  case '2':
    grabamemo(1, valores);
    break;
  case '3':
    grabamemo(2, valores);
    break;
  case '4':
    grabamemo(3, valores);
    break;
  case '5':
    grabamemo(4, valores);
    break;
  case '6':
    grabamemo(5, valores);
    break;
  case '7':
    grabamemo(6, valores);
    break;
  case '8':
    grabamemo(7, valores);
    break;
  case '9':
    grabamemo(8, valores);
    break;
  case '0':
    grabamemo(9, valores);
    break;
  case 'A':
    grabamemo(10, valores);
    break;
  case 'B':
    grabamemo(11, valores);
    break;
  case 'C':
    grabamemo(12, valores);
    break;
  case 'D':
    grabamemo(13, valores);
    break;
  }
  }
  while (key != 'F');
}
void grabamemo(int pos, byte valores)        //saving to the EEPROM function
{
  EEPROM.write(memo[pos], valores);
}
void enviamemo(int pos)                      //function to send the preset saved on the EEPROM adress to the 74HC595
{
  digitalWrite(bypassled, LOW);
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, memo[pos]); 
  digitalWrite(latchPin, HIGH);
}
void modobypass()
{
  digitalWrite(bypassled, HIGH);
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, memo0); 
  digitalWrite(latchPin, HIGH);

}

Sometimes I'm really thinking about the "easy option" using a bigger Atmel microcontroller........
35  Using Arduino / Project Guidance / Re: Arduino doesn't do what I've written in the code on: March 05, 2013, 07:16:24 pm
Well.....Skorn I did what you say, I toke the calling to guardamemoria(valores) after the Led state bit writing operation and I insert another do...while loop for the guardamemoria function so that it stays in the switch....case routine till I press the 'F' key, now that is working correct and the programm doesn't goes directly to the Led blinking routine, but now I see that the arduino stays in this part of the programm and it doesn't respond to any key press, including the 'F' key........can it be that the way I'm using to store every bit in the byte valores isn't correct? It's posible to read the values of the ledPins array and store it in the byte valores in an easier way?
Thanks for your help, I'm still new at Arduino (not in electronic), but I'm learning new things everyday from people like you who helps to understand how it all works.
36  Using Arduino / Project Guidance / Re: Arduino doesn't do what I've written in the code on: March 05, 2013, 05:55:44 pm
Ok, now the switch/case routine works, but now the circuit skips the next function called void guardamemoria, it goes directly to the three times blinking led routine and exit to the main function (void loop).........
I have read in this forum that it's possible to read the state of the output pins with the digitalRead function and not only the input pins, is this correct?
Thanks for your help, now I'm a bit nearer to the ending of this project.
37  Using Arduino / Project Guidance / Re: Arduino doesn't do what I've written in the code on: March 05, 2013, 01:42:43 pm
Ok, now I understand what you're saying........I'll try to put the break after each case command, later I will try the hardware part.
Thanks all for your suggestions and help, I'll keep you informed about the project.
38  Using Arduino / Project Guidance / Re: Arduino doesn't do what I've written in the code on: March 05, 2013, 10:51:50 am
You need to break from each case statement.  This won't break you out of the do loop but break you out of the switch statement. 

That's exactly what I don't want, so I do what it says here:

Quote
Without break, the program continues to the next case, executing the statements until a break or the end of the statement is reached. In some situations, this continuation may be desirable.

Thanks for comment.
39  Using Arduino / Project Guidance / Re: Arduino doesn't do what I've written in the code on: March 05, 2013, 10:15:03 am
Skorn: No errors this time in the compilation, will try the modifed code when I have the circuit by hand, thanks.

Henry_Best: There are no break statements because I want to stay in the switch/case loop till the 'E' key is pressed.

CrossRoads: Here is the DigitalToggle library, by the other way, like I said before in the void loop() function the keypad works perfect, so I don't think that changing the name would help. I have to say that I have done many changes to the code before posting it here in the Forum, I have compiled the code without any problem or errors, but after programming the Arduino, it doesn't do what it is supposed to do.
I am starting to think that maybe it could be better use a bigger Atmel like the sanguino does and to use directly one pushbutton with every I/O pin instead the keypad, could it be possible that the keypad have problems to work right when I call it from a function that isn't the main loop function?
Thanks for your answers and suggestions.
40  Using Arduino / Project Guidance / Re: Arduino doesn't do what I've written in the code on: March 04, 2013, 11:24:14 pm
I have quickly tried the change that Skorn suggested me on the Arduino IDE and when I verify it says:
error: ‘key’ was not declared in this scope
So......I am stuck like before, I have tried many options before I posted the code in the Forum like use a while (key !='E') and then the switch/case routine........but it doesn't worked, I've tried to put the 'E' key in one of the cases in the switch/case routine but it doesn't worked also.....I'm still thinking about the 232.345.249 reasons why it doesn't work........so if I have some help you are welcome, hahahha.
Thanks for give me some of your time and sorry if my english is not very clear but I'm more used to read and hear it than to write and speak it.
41  Using Arduino / Project Guidance / Re: Arduino doesn't do what I've written in the code on: March 04, 2013, 11:08:05 pm
Skorn I'll try that change tomorrow, today I'm out of time to do more things, so I will post tomorrow the result of the change.

CrossRoads, It is inside of void modoPrograma() and is part of this function.
What I want in this function is that the switch/case routine works till I finish it pushing the 'E' button from the keypad, meanwhile the 1-8 pushbuttons have to toggle the programming leds, that's the reason that I use a do....while loop to keep the programm in the switch/case routine till I finish it myself.
Thanks for the help, tomorrow I will keep you all informed about this.
42  Using Arduino / Project Guidance / Re: Arduino doesn't do what I've written in the code on: March 04, 2013, 09:52:09 pm
Well.......I am using the keypad library and I suppose that the library does all this configuration itself once I have defined the Keypad layout.
The Keypad works perfect in the loop function but not in the programming function.......can it be that I cannot use the keypad outside of the loop function to do other things?
Thanks.
43  Using Arduino / Project Guidance / Arduino doesn't do what I've written in the code (FIXED). on: March 04, 2013, 09:31:24 pm
Hello, I have a problem with my code, when I call a function Arduino does part of the command, but after this I have a switch/case function that the Arduino doesn't execute.......anyone knows why? It uses the DigitalToggle library but if I push any button the state of the Leds doesn't change.
Here's the code:
Code:
/*
Using 8 outputs and saving output presets in the EEPROM
 */
#include <Keypad.h> //Inlcude Keypad Library
#include <EEPROM.h>                            //Include EEPROM Library
#include <DigitalToggle.h>      //Include DigitalToggle Library
int ledPins[] = {
  0,1,2,3,4,5,6,7};              //Defining program mode Leds
int bypassled = 11;                           //Defining the bypass Led
int latchPin = 14;      //Defining latchPin from the 74HC595
int clockPin = 15;      //Defining clockPin from the 74HC595
int dataPin = 13;      //Defining dataPin from the 74HC595
const byte filas = 4; // rows of the Keypad
const byte colus = 4; // columns of the Keypad
char teclas[filas][colus] = {       //mapping the Keypad layout
  {
    '1', '2', '3', '4'             }
  ,
  {
    '5', '6', '7', '8'             }
  ,
  {
    '9', '0', 'A', 'B'             }
  ,
  {
    'C', 'D', 'E', 'F'             }
};

// defining the pins that are used for the rows and columns of the Keypad

byte filaPins[filas] = {
  16, 17, 18, 19 };
byte coluPins[colus] = {
  8, 9, 10, 12 };      
Keypad teclado = Keypad( makeKeymap(teclas), filaPins, coluPins, filas, colus );
byte dataOut = 0;
byte valores = 0;
int bit = 0;
byte memo0 = B00000000;                  //the bypass value is always the same, so it's not necessary to save it in the EEPROM
byte memo[] = {
  0,5,10,15,20,25,30,35,40,45,50,55,60,65};  // defining the EEPROM adresses

void setup()
{
  for(int index = 0; index <= 8; index++) //defining output pins
  {
    pinMode(ledPins[index], OUTPUT);
  }
  pinMode(bypassled, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  for(int index = 0; index <= 7; index++)
  {
    digitalWrite(ledPins[index], LOW); // shutdown the programming Leds
  }
  digitalWrite(bypassled, HIGH); // lighting the bypass Led
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, memo0);  
  digitalWrite(latchPin, HIGH);
  delay(1000); //wait a second........
}
void loop()
{
  teclado.setDebounceTime(10);
  char key = teclado.getKey();
  switch(key) //the key we select sends a memory content assigned to this key
  {        
  case '1':
    enviamemo(0);                              
    break;
  case '2':
    enviamemo(1);
    break;
  case '3':
    enviamemo(2);
    break;
  case '4':
    enviamemo(3);
    break;
  case '5':
    enviamemo(4);
    break;
  case '6':
    enviamemo(5);
    break;
  case '7':
    enviamemo(6);
    break;
  case '8':
    enviamemo(7);
    break;
  case '9':
    enviamemo(8);
    break;
  case '0':
    enviamemo(9);
    break;
  case 'A':
    enviamemo(10);
    break;
  case 'B':
    enviamemo(11);
    break;
  case 'C':
    enviamemo(12);
    break;
  case 'D':
    enviamemo(13);
    break;
  case 'E':
    modobypass();              //In case we select the 'E' key we set the bypass mode
    break;
  case 'F':
    modoPrograma();            //if we select the 'F' key we are entering in the programming mode
    break;
  }
}  
void modoPrograma()
{
  digitalWrite(bypassled, LOW);
  {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, memo0);  
    digitalWrite(latchPin, HIGH);
    delay(500);
    for (int i = 0; i <= 2; i++)
    {
      for(int index = 0; index <= 7; index++)
      {
        digitalWrite(ledPins[index], HIGH); // we make blink the programming Leds three times, so we know that we are entering programming mode
      }
      delay(500);
      for(int index = 0; index <= 7; index++)
      {
        digitalWrite(ledPins[index], LOW);
      }
      delay(500);
    }
  }
  {
    char key = teclado.getKey();           //THIS IS THE PART OF THE CODE THAT DOESN'T WORK!!!!
    do
    {
    switch(key)
    {              
    case '1': //Now we select which outputs we want to have ON or OFF
      digitalToggle(ledPins[0]);                //The programming Leds shows us which Output will be ON or OFF
    case '2': //in the preset, every Led corresponds to an Output.    
      digitalToggle(ledPins[1]); //we use the digitalToggle library to change the state of each Led
    case '3':
      digitalToggle(ledPins[2]);
    case '4':
      digitalToggle(ledPins[3]);
    case '5':
      digitalToggle(ledPins[4]);
    case '6':
      digitalToggle(ledPins[5]);
    case '7':
      digitalToggle(ledPins[6]);
    case '8':
      digitalToggle(ledPins[7]);
    }
  }
while (key != 'E');                                  //If we press the 'E' key we go to the next step
}
  for(int i=0; i <= 7; i++) //we save every Led state in the byte valores
  {
    bitWrite(valores, bit, digitalRead (ledPins[i]));
    bit = bit + 1;
    guardamemoria(valores); // calling the save function
    {
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, memo0);  
      digitalWrite(latchPin, HIGH);
      delay(500);
      for (int i = 0; i <= 2; i++)
      {
        for(int index = 0; index <= 7; index++)
        {
          digitalWrite(ledPins[index], HIGH); // we make blink the programming Leds three times, so we know that we are exiting programming mode
        }
        delay(500);
        for(int index = 0; index <= 7; index++)
        {
          digitalWrite(ledPins[index], LOW);
        }
        delay(500);
      }
    }  
  }
}
void guardamemoria(byte valores) //function to save the byte valores in the EEPROM, this byte contains the preset information that we have programmed
{
  char key = teclado.getKey();
  switch(key) //Now we select in which adress of the EEPROM we want to save the Byte value
  {
  case '1':
    grabamemo(0, valores);              
    break;
  case '2':
    grabamemo(1, valores);
    break;
  case '3':
    grabamemo(2, valores);
    break;
  case '4':
    grabamemo(3, valores);
    break;
  case '5':
    grabamemo(4, valores);
    break;
  case '6':
    grabamemo(5, valores);
    break;
  case '7':
    grabamemo(6, valores);
    break;
  case '8':
    grabamemo(7, valores);
    break;
  case '9':
    grabamemo(8, valores);
    break;
  case '0':
    grabamemo(9, valores);
    break;
  case 'A':
    grabamemo(10, valores);
    break;
  case 'B':
    grabamemo(11, valores);
    break;
  case 'C':
    grabamemo(12, valores);
    break;
  case 'D':
    grabamemo(13, valores);
    break;
  }
}
void grabamemo(int pos, byte valores)        //saving to the EEPROM function
{
  EEPROM.write(memo[pos], valores);
}
void enviamemo(int pos)                      //function to send the preset saved on the EEPROM adress to the 74HC595
{
  digitalWrite(bypassled, LOW);
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, memo[pos]);  
  digitalWrite(latchPin, HIGH);
}
void modobypass()
{
  digitalWrite(bypassled, HIGH);
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, memo0);  
  digitalWrite(latchPin, HIGH);
}
Thanks for the help folks!
44  International / Español / Re: Pregunta de novato absoluto... on: January 19, 2013, 10:20:00 am
kerheol, si te manejas bien con el inglés te recomiendo dos libros que encontrarás fácilmente por internet:
Arduino Cookbook y Beginning Arduino
Yo soy novato en Arduino, no así en la electrónica ni en el mundillo de los microcontroladores, ya he trabajado con PIC's programándolos en BASIC, pero Arduino ha sido como empezar de cero y la verdad es que leer esos dos libros me ha facilitado mucho el comprender como funciona esta plataforma de desarrollo.
Por cierto, yo tengo una placa Arduino UNO comprada en dx y es igual que la de las fotos.....
Salu2.
45  International / Software / Re: Duda sobre TX y RX on: January 16, 2013, 02:56:29 pm
Estupendo, muchísimas gracias por aclararme la duda.
Salu2.
Pages: 1 2 [3] 4