Problem with 4D systems display code halting main loop...?!?!?!?

Hi all,

Im relatively new to C++ although i know my way around...

I have been having some trouble with the following code.

The code is counting the state of D2, de bouncing it (because of reed switch) and then sending the int buttonCounter over serial to the display.

#include <genieArduino.h>


const int buttonPin = 2;    // reed pin
const int ledPin = 13;      // LED pin

// Variables will change:
int ledState = HIGH;         // the current state of the output pin
int buttonState;             // the current reading from the input pin
int lastButtonState = HIGH;   // the previous reading from the input pin
int buttonCounter = 0;

unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 2;    // the debounce time; increase if the output flickers

//GENIE
Genie genie;
#define RESETLINE 4

void setup() {
  Serial.begin(9600);  // Serial0 @ 9600 Baud
   genie.Begin(Serial);   // Use Serial0 for talking to the Genie Library, and to the 4D Systems display
   Serial.setTimeout(100);

  pinMode(RESETLINE, OUTPUT);  // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
  digitalWrite(RESETLINE, 1);  // Reset the Display via D4
  delay(100);
  digitalWrite(RESETLINE, 0);  // unReset the Display via D4

  delay (3500); //let the display start up after the reset (This is important)

  genie.WriteContrast(15); 

  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);

  // set initial LED state
  digitalWrite(ledPin, ledState);
  digitalWrite(buttonPin, HIGH);
}

void loop() {
  // read the state of the switch into a local variable:
  int reading = digitalRead(buttonPin);

  // check to see if you just pressed the button
  // (i.e. the input went from LOW to HIGH),  and you've waited
  // long enough since the last press to ignore any noise:

  // If the switch changed, due to noise or pressing:
  if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:

    // if the button state has changed:
    if (reading != buttonState) {
      buttonState = reading;

      // only toggle the LED if the new button state is HIGH
      if (buttonState == LOW) {
        ledState = !ledState;
        buttonCounter++;
        genieWrite ();
      }
    }
  }

  // set the LED:
  digitalWrite(ledPin, ledState);
  Serial.println(buttonCounter);
  //genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0, buttonCounter); //Talk to the display

  // save the reading.  Next time through the loop,
  // it'll be the lastButtonState:
  lastButtonState = reading;
}


void genieWrite() {
  genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0, buttonCounter); //Talk to the display
}

the genie.WriteObject line seems to halt all of the other functions, they still work but only very slowly... its almost like there is a massive delay at the end of the main loop...

the information does get to the display aswell, but it is the same as the ledstate in that is is very slow and seems to only trigger if you hit the reed at the right time..?

any ideas?

Mitch

  Serial.begin(9600);  // Serial0 @ 9600 Baud
   genie.Begin(Serial);   // Use Serial0 for talking to the Genie Library, and to the 4D Systems display
   Serial.setTimeout(100);

There is NO such thing as Serial0 on ANY Arduino.

The setTimeout() method is used to determine how long to wait for data. Since you don't read anything from the serial port, it is pointless.

any ideas?

Sure thing. Post a link to the library. You have a problem; you post a link to the library that you think is causing the problem(s).

You should also comment out the call, to see if that is, indeed, where the problem is.

Paul,

Still lost...

i realise that there is no such thing at serial0, i was using multiple serial ports and this made it easier to understand... however this is not the problem?

call?

Paul,

oh, you mean the header file....

Here :slight_smile:

and yes, it is the call..

it was originally within the main loop, and when i commented it out, the code works fine...
i tried making a different function for the call to see if that helps, but no luck.. same result

cheers

Perhaps you should try using something other than a "cool gauge" as the means for displaying the value. I suspect that a "cool gauge" involves a lot of graphics, and will be slow to draw.