Go Down

Topic: Arduino Programming error? (Read 2 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.

Go Up