Go Down

Topic: Arduino Programming error? (Read 2641 times) previous topic - next topic

Grootvalk


Quote
You mean i must make a lot of Void ?

Don't understand your question.. please rephrase




void displayError(int code)
{
  lcd.setCursor (0 , 0 );
  lcd.print("Error 01");
  lcd.setCursor (0 , 1 );
  lcd.print("Code 000");
  C = code;
}

I need 255 diff of these, so i always get the problem of my ram, because i  use 255 if's for this.

AWOL

This time shorter still, and avoiding the error-prone A0/14 etc duality:
Complete with leading zeros.
Code: [Select]
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd( 7, 6, 5, 4, 3, 2);

int A = 0;
int B = 0;
int C = 1;

const byte inputPins [8] = {A0, A1, A2, A3, A4, A5, 8, 9};

void displayError(int code)
{
  lcd.setCursor (0 , 0 );
  lcd.print("Error 01");
  lcd.setCursor (0 , 1 );
  lcd.print("Code    ");
  lcd.print(code / 100);
  lcd.print((code % 100) / 10);
  lcd.print(code % 10);
  C = code;
}

void setup()
{
  // Define Output
  pinMode(13, OUTPUT); // sets the digital pin as output LED
  // Define Input
  for (int i = 0; i < 8; ++i) {
    pinMode(inputPins [i], INPUT);
    digitalWrite(inputPins [i], HIGH);
  }   

  // set up the LCD's & Company Logo:
  lcd.begin(40, 2);
  Serial.begin(9600);
}

void loop()
{
  if (A == 0 )
  {
    for (int i = 0; i < 8; ++i) {
      bitWrite (B, i, !digitalRead(inputPins [i]));
    } 

    if (B == C)
    {
      A = 10;
    }
    else {
      lcd.clear();
      A = 5;
    }
  } // End A == 0

  if (A == 5 )
  {
    displayError(B);  // call to function above
    A = 10;
  } // End A == 5


  if (A == 10 )
  {
    delay(100);
    Serial.println();
    Serial.println(A);
    Serial.println(B);
    Serial.println(C);
    A = 0;
  } // End A == 10

} // End of Loop
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

robtillaart

#32
Apr 18, 2011, 11:21 am Last Edit: Apr 18, 2011, 11:24 am by robtillaart Reason: 1
you don't understand the concept of a function.

A function is a piece of code you can give a parameter too. You have used them when you did   pinMode(14, INPUT);  that is a function with two parameters

void displayError(int code)     // code is a parameter
{
 lcd.setCursor (0 , 0 );
 lcd.print("Error 01");
 lcd.setCursor (0 , 1 );
 lcd.print("Code    ");
 lcd.print(code);                // it is filled in here
 C = code;                        // and here
}


defines a function with one parameter, which is of the type integer, just like the vaiable B which you want to display.

IN the code I submitted to There is one line   -   displayError(B);
When it is executed by the CPU it fills in the actual value for B, e.g 187

The actual  function call becomes displayError(187) and the CPU will assigne the value 187 to the variable code use that value everywhere where code is mentioned:

Then you might read it like:

void displayError(187)     // code is a parameter
{
 lcd.setCursor (0 , 0 );
 lcd.print("Error 01");
 lcd.setCursor (0 , 1 );
 lcd.print("Code    ");
 lcd.print(187);                // it is filled in here
 C = 187;                        // and here
}


Does this makes sense to you?
Please run the code I send to you and check if it does what you expect.

--- update ---
basics of C programming : http://www.macs.hw.ac.uk/~rjp/Coursewww/Cwww/index.html

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Grootvalk

That coding makes sense to me.

Thanks for that code.

It works but not for me. Because all codes will be replaced with text using a form.
and which are not asigned will show:
Upperling: error 01 ( Code unprogrammed )
Lowerline: Code ( Byte 0-255 )

AWOL

#34
Apr 18, 2011, 11:35 am Last Edit: Apr 18, 2011, 01:49 pm by AWOL Reason: 1
Grootvalk:
From our PMs and your previous posts, I get the impression that you think this forum is a source of tailor-made solutions for your particular problems.

It is time for you to realise that this is not the case.

People here will post solutions based on their perceived best-practice in any given set of circumstances.
The better you express your problem, the closer (probably) to an ideal solution will be the responses.
You still have to put in some effort.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Nick Gammon

Quote from: Grootvalk

The HTML form only generates the cade ATM. su copy paste compile and upload.

...

Thanks for that code, but its just without my error code thins which i must have. with yours i can only use 1 error. but checking out the RAM.

Worst case is that i have to send characters manually?

...

I need 255 diff of these, so i always get the problem of my ram, because i  use 255 if's for this.

...

You mean i must make a lot of Void ?

...

It works but not for me. Because all codes will be replaced with text using a form.
and which are not asigned will show:
Upperling: error 01 ( Code unprogrammed )



Look, clearly English isn't your first language. But if you are going to use Google translate (or whatever) try translating back into your native language first and checking it makes sense.

ie.

Code: [Select]
<your language> -->  English  --> <your language>


You are talking nonsense. We can't help you.

You haven't clearly defined what you are trying to achieve, except that some error message might appear on an LCD screen, centered.

The short answer is, that your machine-generated code is too large. You need to understand C better to work out a way of generating better code. I don't care if it comes from HTML, Java, Lua or some friendly dolphins.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

AWOL

Your problem with the automatically generated code is that it uses too much RAM.
Every time you have "Code XXX", that's another nine bytes of RAM gone.

If you want to persist using the generated code, you're going to have to modify the code generator to put the strings into PROGMEM, but, as noted earlier, you're probably running short on that too.

Time for a rethink.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

AWOL

#37
Apr 18, 2011, 12:05 pm Last Edit: Apr 18, 2011, 12:07 pm by AWOL Reason: 1
OK, I think I have a handle on this now.

You have a form that allows you to associate specific conditions (inputs 0...255) with a label.
If you enter a label, you want that label displayed if the Arduino sees that condition.
If you don't enter a label on the form, the message displayed is simply the condition value.

Is that correct?

One approach is to enumerate all the non-default labels.
Put all the labels and their condition codes in a table.
When a condition occurs, search through the list of non-defaults.
If a match is found, display the given label, otherwise display the numeric value of the condition.

This does not require 1500 lines of code - just a slightly smarter code generator.
Or an even dumber code generator that simply outputs a table that is pasted into a template sketch.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Nick Gammon

#38
Apr 18, 2011, 12:52 pm Last Edit: Apr 18, 2011, 12:54 pm by Nick Gammon Reason: 1

Every time you have "Code XXX", that's another nine bytes of RAM gone.


I'd forgotten about that. The literal messages like "Code XXX" take 9 bytes of RAM (8 plus the 0x00 at the end). This is copied from program memory into RAM at program startup. 9 x 255 is 2295, so that is all of your RAM gone (you have 2048 on the Uno). Even 9 x 180 is 1620 which is most of it.

This isn't a PC with 1 Gb of RAM. You have to look carefully at what memory your code takes, and if you are generate a block of 255 x <something> then that something had better be pretty small.

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Grootvalk

Thanks for the help all.
Even with labels i get a short of memory, we have decided to let it be what it is.

We use the RAM to the max which i was afraid of at the beginning. But since they really want Arduino and nothing else this it is not my fault.

I Will reveal some code for you.
the code is changing the "g" as a character, since our new LCD makes him ugly, and the old LCD is out of the market.
If this is for your use go to: http://pastebin.com/ReHfN5uc

I cut almost 95% of the script out so the converter is left.

Thank all of you, I did use new commands and i've learned something :)


u0421793


AWOL

Is this a Chuckle Brothers sketch?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Nick Gammon


Well i learned to write HTML and JAVA so the code just pops out.



It acts like a converter of my PLC which sends a byte to my Arduino Nano, Which will be converted from 24V to 5V using 78L05Z and a optocoupler.



When checking in Bascom AVR what the error rate is.. it is almost 8%.



But since they really want Arduino and nothing else this it is not my fault.



the code is changing the "g" as a character, since our new LCD makes him ugly

...

Thread Closed to me


Glad we could help out.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up