First post, trying to use analogbuttons instead of DFR_key

Hi!
I hope this is not in the wrong forumpart, please direct me to correct one if that is the case.
First some background info may be interesting.
I am rather new to programming in general and to arduino, but i think i have som basic knowledge in how programming and electronics works, and i have been fiddling a bit with arduino the past month or so and i think i have come a bit on the way.
This is my first "serious" project on arduino, and it is to create a ceramic kiln controller with ramping, hold and continue fases. I have borrowed some code from different sketches and are trying to modify it to suit my needs, but i have run into problems now. The thing i am trying to accomplish is to use the code from Meltinator 9000 but use it with my shield that uses analogbottons on A0 instead of the shild from adafruit he is using, but i really don't know how define the "buttons" class now, and i get the folloving errors when i try to compile:

Sorry if i am not folloing forum rules correctly, i am still learning, please bear with me, i had to cut the code becuase it is on 20000 characters, how do i attach such a "big" sketch?

Sincerley
Parkeringskungen from sweden

odd.ino:105:1: error: ‘buttons’ does not name a type
odd.ino: In function ‘void loop()’:
odd.ino:150:3: error: ‘buttons’ was not declared in this scope
odd.ino:150:26: error: expected primary-expression before ‘.’ token

#include <Wire.h>
// #include <Adafruit_MCP23017.h>
// #include <Adafruit_RGBLCDShield.h>
#include <EEPROM.h>
#include "Adafruit_MAX31855.h"
#include <LiquidCrystal.h>
//#include <DFR_Key.h>
#include "AnalogButtons.h"
 
int thermoDO = 3;
int thermoCS = 4;
int thermoCLK = 5;
Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);
// Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 

int state = 1;
//The states are as follows:
//  1: navigation - Main Menu       
//  2: Navigation - Run Menu        
//  3: Navigation - Edit Menu       
//  4: editing an existing program  
//  5: running                       
//  6: Creating a new program       

int currStep = 1;               //This is the program step currently being edited.  
int currCharVal = 65;           //This integer will be used to cycle through characters when the user names a new program.  
int statechange = 1;
int cursorHoriz = 1;            //This is the horizontal cursor location.
int cursorVert = 1;             //This is the certical cursor location.
int currentProg = 1;            //This is the currrently selected program.
int currentActualTemp = 70;     //The current actual temperature.
int currentTargetTemp = 70;     //This is the current target temperature;
int tempUpdateDelay = 3000;     //This is the time between relay actions in milliseconds.
int eepromAddress = 0;
byte numProgs;                  //This is the total number of stored programs, written to the first byte of the EEPROM memory.
char name1[11] = "          ";  //This is the name of the currently selected program
char name2[11] = "          ";  //This is the name of the program after the currently selected program
char newName[11] = "          ";
unsigned long progStartTime;
unsigned long currTime;
double elapsed = 0;
double currTemp = 0;
double planTemp = 0;
byte Tmp = 0;                  //Temperature in tens of degrees Celcius
byte Rte = 0;                  //Rate in tens of degrees per hour
byte Hld = 0;                  //Hold time in minutes
int prgStart = 0;              //This is the initial memory address of the currently selected program
int heatIncreaseFlag = 1;

int currStage = 0;
double currInitTemp = 0;
double currTgtTemp = 0;
int currRate = 0;
unsigned long currStageStartTime = 0;
unsigned long currRunTime = 0;
int currStageState = 3;        //1 = heating, 2 = holding, 3 = stage finished
unsigned long currHoldTime = 0;
//double currTemp = 0;
unsigned long holdStartTime = 0;
int runflag = 0;

//I'll use pin 13 for the relay controller, because it already has an indicator LED on the Arduino UNO board.

// #define WHITE 0x7

//DFR_Key keypad;

#define ANALOG_PIN 0
void handleButtons(int id, boolean held);

AnalogButtons analogButtons(ANALOG_PIN, 30, &handleButtons);
Button BUTTON_LEFT = Button(1, 1013,1014);
Button BUTTON_RIGHT = Button(2, 1002, 1002);
Button BUTTON_SELECT = Button(3, 970, 971);
Button BUTTON_UP = Button(4, 929, 933);
Button BUTTON_DOWN = Button(5, 860, 875);


//int localKey = 0;
String keyString = "";

void setup() {
  // Debugging output
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  //int time = millis();
  lcd.print("MELTINATOR 9000 ");//("Initializing...");
  lcd.setCursor(0,1);
  lcd.print("LezBurnSumStuff!");
  delay(2000);
  //time = millis() - time;
  //Serial.print("Took "); Serial.print(time); Serial.println(" ms");
  // lcd.setBacklight(WHITE);
}

// uint8_t i=0;
void loop() {
  //Serial.begin(9600);
  //Serial.print("Iteration...\n");
  //Serial.print(state);
  //Serial.print("\n");
  //Serial.print(runflag);
  //Serial.print("\n");
  Serial.print(currStageState);
  Serial.print("\n");
  Serial.print(currTgtTemp);
  Serial.print("\n");
  Serial.print(currRate);
  Serial.print("\n");
  Serial.print(currRunTime);
  Serial.print("\n");
  Serial.print(currInitTemp);
  Serial.print("\n");
  Serial.print(planTemp);
  Serial.print("\n");
  Serial.print("\n");
  //This first "if" loop is to allow the loop to run freely if the program is in the "run" state (5).  
  //if (state!=5) {
    // uint8_t buttons = lcd.readButtons();
  buttons = AnalogButtons.checkButtons();
  //}
  //else {
  //  uint8_t buttons = 1;
  //  statechange = 1;
  //}
  if ((buttons)||(state==5)) {
    runflag = 1;
  }
  else {
    runflag = 0;
  }
  if ((runflag)||(statechange)) {
  //if ((buttons)||(statechange)) {
    statechange = 0;
  switch (state) {
    case 1:
      //State:Navigation - Main Menu
      //Draw the Main Menu screen
      lcd.clear();
      lcd.setCursor(0,0);
      //lcd.blink();
      lcd.print("Main Menu       ");
      lcd.setCursor(0,1);
      switch (cursorHoriz) {
        case 1:
          lcd.print("*Run _Edit _New ");
          break;
        case 2:
          lcd.print("_Run *Edit _New ");
          break;
        case 3:
          lcd.print("_Run _Edit *New ");
          break;
      }
      //Place the cursor in the appropriate location
      //Allow the user to move the cursor location and press enter.
      if (buttons) {
        if (buttons & BUTTON_LEFT) {
          cursorHoriz = cursorHoriz - 1;
          statechange = 1;
        }
        if (buttons & BUTTON_RIGHT) {
          cursorHoriz = cursorHoriz + 1;
          statechange = 1;
        }
        //Keep the cursor location valid:
        cursorHoriz = constrain(cursorHoriz,1,3);

Nowhere in your code you have declared a variable called buttons. Possibly because you commented out a line as shown below

// uint8_t buttons = lcd.readButtons();
buttons = AnalogButtons.checkButtons();

Change it to

// uint8_t buttons = lcd.readButtons();
uint8_t buttons = AnalogButtons.checkButtons();

Thanks for your reply, unfortunatley it did not work, i got error

odd2.ino: In function ‘void loop()’:
odd2.ino:153:34: error: expected primary-expression before ‘.’ token
odd2.ino:190:21: error: no match for ‘operator&’ (operand types are ‘uint8_t {aka unsigned char}’ and ‘Button’)
odd2.ino:194:21: error: no match for ‘operator&’ (operand types are ‘uint8_t {aka unsigned char}’ and ‘Button’)

I have attached my complete sketch as is now in a .ino file, i hope that is ok?

It feels like i am overlooking some kind of basic undertanding here, is it so?

/Johan

kilnhelp.ino (20.7 KB)

I have never used the analogbuttons library so can't be of too much help. I assume Arduino Playground - AnalogButtons is the one you use?

According to the source code, checkButtons() does not return anything. Instead you're supposed to have a so-called callback function. You have added a prototype for it (void handleButtons(int id, boolean held)) but you don't have an implementation.

I suggest that you start with the example and try to understand how it works. This is the example code extracted from the above link.

/*
  AnalogButtons,
  
  created 02 Jan 2009 V 0.1
 
 Connect more than one button to a single analog pin, 
 register a call-back function.which gets called when a button
 is pressed or held down for the defined number of seconds. Includes
 software key debouncing which may need to be adjusted, the the second 
 argument to AnalogButtons class. Define the ANALOG_PIN in the constructor
 of AnalogButtons.
 
 The circuit:

 * 5 buttons, 1 side of all buttons connected together to +5V. 
   The other side of each button is connected via a different value
   resister (tested with) 1k, 2k5, 5k8, 10k, 18k to one side of a
   100k resister which is in turn connected to GND. At the point
   where all the different resisters are joined you make a connection
   to your analog input. Basicly a different voltage divider is setup 
   depending upon which button is pressed. You have to configure the 
   Buttons Hi/Low values, see the comments in example code below and the
   AnalogButtons::configure(ANALOG_PIN) function.
   
   More or less than 5 buttons could be added, just pick different values
   of the resister sot hat all buttons have different values which arn't too
   close in size.
   
   I'm not sure what happens when Arduino is powered from batteries and Power V
   drops below V5.
 
 by Neil DUdman and everyone who's ever used Arduino
 
 */
#include "AnalogButtons.h"

#define ANALOG_PIN 0

// A call back function that you pass into the constructor of AnalogButtons, see example
// below. Alternitivly you could extend the Button class and re-define the methods pressed() 
// or held() which are called 
void handleButtons(int id, boolean held)
{  
  if (held) {
    Serial.print("button id="); Serial.print(id); Serial.println(" was pressed and held"); 
  } else{
    Serial.print("button id="); Serial.print(id); Serial.println(" was pressed only");
  }
}

AnalogButtons analogButtons(ANALOG_PIN, 30, &handleButtons);
Button b1 = Button(1, 1013,1014);
Button b2 = Button(2, 1002, 1002);
Button b3 = Button(3, 970, 971);
Button b4 = Button(4, 929, 933);
// Default hold duration is 1 second, lets make it 5 seconds for button5
Button b5 = Button(5, 860, 875, 5);

void setup() 
{
  Serial.begin(9600); 
  Serial.println("Testing your Analog buttons");
  
  analogButtons.addButton(b1);
  analogButtons.addButton(b2);
  analogButtons.addButton(b3);
  analogButtons.addButton(b4);
  analogButtons.addButton(b5);  
 }
 
void loop() 
{  
  // To check values when button are pressed
  analogButtons.checkButtons();
  
  // To configure the MAX/Min values for each 
  // Button, uncomment this line, make sure you've called Serial.begin(9600); 
  // Then in turn hold town each botton, noting the max/min values
  //AnalogButtons::configure(ANALOG_PIN); //delay(1000);
}

I hope this helps.