Arduino Programming error?

so ive created all this for an easy work and everyone can program

Imagine how much more work you could get done, if you didn't have to do all that typing.

I only have to change some values in the HTML page and simply press convert and done.

But i cant get it right now, cus it fails.

Grootvalk:
and the text will get centered in the midle of the LCD, so it gets different yes.

Centering text at runtime is pretty trivial stuff.

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

Can i change it somewhere?

Can you quote the documentation on that?

I only have to change some values in the HTML page and simply press convert and done.

And then what? You deploy these gadgets?

The HTML thing is for real. check http://img39.imageshack.us/i/wwwud.jpg/

I was hoping for a picture of the end-product. Whatever it does.

I do an Electric, Installatin, Designer and construction education.

That's great that you are doing all this. But if I may humbly suggest, a bit more practice on the programming side before you write HTML code that produces C++ code that runs on a microprocessor.

But i cant get it right now, cus it fails

Time for a new approach.

[quote author=Nick Gammon link=topic=58817.msg423089#msg423089 date=1303115199]

Grootvalk:
and the text will get centered in the midle of the LCD, so it gets different yes.

Centering text at runtime is pretty trivial stuff.

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

Can i change it somewhere?

Can you quote the documentation on that?

Documentation for Error % can be found at: WormFood's AVR Baud Rate Calculator Ver. 2.1.1
BAscom AVR has a built-in error shown, just set it to 16MHZ and baudrate you have an the rror % is shown.

I only have to change some values in the HTML page and simply press convert and done.

And then what? You deploy these gadgets?

The HTML thing is for real. check ImageShack - Best place for all of your image hosting and image sharing needs

I was hoping for a picture of the end-product. Whatever it does.

I do an Electric, Installatin, Designer and construction education.

That's great that you are doing all this. But if I may humbly suggest, a bit more practice on the programming side before you write HTML code that produces C++ code that runs on a microprocessor.
[/quote]The HTML form only generates the cade ATM. su copy paste compile and upload.

Hi Grootvalk,

I had a quick look at your code and I think you are running out of variable RAM, an Arduino has only 2K.

You need to use functions to eleminate double typing as Nick said. As I am in a very good mood today I did that for you (also to move the discussion forward). The code below is ~100 lines iso 2000(?), it compiles and as far as I can see it does almost the same as yours (the leading zero's in the display are missing). So try this code and let us know if it works for you.

Succes,
Rob

#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;

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

void setup() 
{
  // Define Output
  pinMode(13, OUTPUT); // sets the digital pin as output LED
  // Define Input
  pinMode(A0, INPUT); // input A0 - Bit 0
  pinMode(A1, INPUT); // input A1 - Bit 1
  pinMode(A2, INPUT); // input A2 - Bit 2
  pinMode(A3, INPUT); // input A3 - Bit 3
  pinMode(A4, INPUT); // input A4 - Bit 4
  pinMode(A5, INPUT); // input A5 - Bit 5
  pinMode( 8, INPUT); // input D8 - Bit 6
  pinMode( 9, INPUT); // input D9 - Bit 7
  // Pull up Resistors
  digitalWrite(A0, HIGH); // Pull up resistor for A0 - Bit 0
  digitalWrite(A1, HIGH); // Pull up resistor for A1 - Bit 1
  digitalWrite(A2, HIGH); // Pull up resistor for A2 - Bit 2
  digitalWrite(A3, HIGH); // Pull up resistor for A3 - Bit 3
  digitalWrite(A4, HIGH); // Pull up resistor for A4 - Bit 4
  digitalWrite(A5, HIGH); // Pull up resistor for A5 - Bit 5
  digitalWrite( 8, HIGH); // Pull up resistor for D8 - Bit 6
  digitalWrite( 9, HIGH); // Pull up resistor for D9 - Bit 7

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


void loop()
{
  if (A == 0 )
  {
    B = 0;
    if (digitalRead(14) == LOW){ 
      B = B + 1; 
    }
    if (digitalRead(15) == LOW){ 
      B = B + 2; 
    }
    if (digitalRead(16) == LOW){ 
      B = B + 4; 
    }
    if (digitalRead(17) == LOW){ 
      B = B + 8; 
    }
    if (digitalRead(18) == LOW){ 
      B = B + 16; 
    }
    if (digitalRead(19) == LOW){ 
      B = B + 32; 
    }
    if (digitalRead( 8) == LOW){ 
      B = B + 64; 
    }
    if (digitalRead( 9) == LOW){ 
      B = B + 128; 
    }

    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

Compiles smoothly => Binary sketch size: 4846 bytes (of a 30720 byte maximum)
Thats far less than the 27K

--- UPDATE ---
If the C++ code is generated from somewhere you must modify the codegenerator accordingly ..

robtillaart:
Hi Grootvalk,

I had a quick look at your code and I think you are running out of variable RAM, an Arduino has only 2K.

You need to use functions to eleminate double typing as Nick said. As I am in a very good mood today I did that for you (also to move the discussion forward). The code below is ~100 lines iso 2000(?), it compiles and as far as I can see it does almost the same as yours (the leading zero's in the display are missing). So try this code and let us know if it works for you.

Succes,
Rob

#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;

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

void setup()
{
  // Define Output
  pinMode(13, OUTPUT); // sets the digital pin as output LED
  // Define Input
  pinMode(A0, INPUT); // input A0 - Bit 0
  pinMode(A1, INPUT); // input A1 - Bit 1
  pinMode(A2, INPUT); // input A2 - Bit 2
  pinMode(A3, INPUT); // input A3 - Bit 3
  pinMode(A4, INPUT); // input A4 - Bit 4
  pinMode(A5, INPUT); // input A5 - Bit 5
  pinMode( 8, INPUT); // input D8 - Bit 6
  pinMode( 9, INPUT); // input D9 - Bit 7
  // Pull up Resistors
  digitalWrite(A0, HIGH); // Pull up resistor for A0 - Bit 0
  digitalWrite(A1, HIGH); // Pull up resistor for A1 - Bit 1
  digitalWrite(A2, HIGH); // Pull up resistor for A2 - Bit 2
  digitalWrite(A3, HIGH); // Pull up resistor for A3 - Bit 3
  digitalWrite(A4, HIGH); // Pull up resistor for A4 - Bit 4
  digitalWrite(A5, HIGH); // Pull up resistor for A5 - Bit 5
  digitalWrite( 8, HIGH); // Pull up resistor for D8 - Bit 6
  digitalWrite( 9, HIGH); // Pull up resistor for D9 - Bit 7

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

void loop()
{
  if (A == 0 )
  {
    B = 0;
    if (digitalRead(14) == LOW){
      B = B + 1;
    }
    if (digitalRead(15) == LOW){
      B = B + 2;
    }
    if (digitalRead(16) == LOW){
      B = B + 4;
    }
    if (digitalRead(17) == LOW){
      B = B + 8;
    }
    if (digitalRead(18) == LOW){
      B = B + 16;
    }
    if (digitalRead(19) == LOW){
      B = B + 32;
    }
    if (digitalRead( 8) == LOW){
      B = B + 64;
    }
    if (digitalRead( 9) == LOW){
      B = B + 128;
    }

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



Compiles smoothly => Binary sketch size: 4846 bytes (of a 30720 byte maximum) 
Thats far less than the 27K

--- UPDATE ---
If the C++ code is generated from somewhere you must modify the codegenerator accordingly ..

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?

Thanks for that code, but its just without my error code thins which i must have.

What are thins? (I'm not native English, sorry)

with yours i can only use 1 error.

No the function displayError() takes care of all your errors defined with the value B (which is set by means of 8 switches)

You mean i must make a lot of Void ?

Worst case is that i have to send characters manually?

Have you tried running my sample code?
If so where did it go wrong?

You mean i must make a lot of Void ?

Don't understand your question.. please rephrase

robtillaart:

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.

This time shorter still, and avoiding the error-prone A0/14 etc duality:
Complete with leading zeros.

#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

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

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 )

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.

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.

<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.

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.

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.