1

I am trying to create a state machine that loops in whatever state it's in until a button is pressed. I am using the Adafruit_RGBLCDShield library along with the LCD shield and 16x2 display. For some reason the buttons aren't being detected at all. Here is the code for one of the states:

    case STANDBY_MODE:
  lcd.clear();
  lcd.setBacklight(0x0);
  delay(100);
  noInterrupts();
  digitalWrite(fire, LOW);
  digitalWrite(chg, LOW);
  digitalWrite(trig, LOW);
  analogWrite(eprgm, 0);
  // Wait for button press
  while(1)
  {
    button = lcd.readButtons();
    if(button)
    {
      showLCD();
      t0 = millis();
      state = NO_CHARGE;
      analogWrite(eprgm, (vSet*0.0204)/5);
      interrupts();
      return;
    }
  }
break; 

In this state, the system turns off all outputs and display and waits for a button to be pressed. For some reason, though, it doesn't respond when I press the button. Is there something missing here?

0

IMO, your post doesn't provide enough information to allow definitive problem diagnosis.

Why do you say noInterrupts(); at line 5? Some versions of the Wire library might be interrupt driven[1]. If interrupts were off, such a library wouldn't detect any button presses on a TWI-interfaced shield like Adafruit's RGBLCDShield.

[1]: Per arduino.cc's WireLibraryDetailedReference page, “"The AVR TWI is byte-oriented and interrupt based...." (section 21.6 on p. 224) ... The TWI module sends an interrupt when it finishes, to notify the processor of the change in conditions ... However, notice that the Wire library has blocking I/O. ” [Ie, the usual Wire library doesn't take advantage of TWI interrupts.]

  • Thanks, this actually WAS the issue. I can't use interrupts with the LCD shield interface. – user20985 May 25 '16 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy