[SOLVED]Int not decleared in this topic

This sketch wil not compile becourse the int count is not decleared in this function. To solve this I made it static but still it wont compile, why??

#include <LiquidCrystal.h>
/* ==== PINS ASSIGNMNET ==========
   LCD RS pin to digital pin 8
   LCD EN pin to digital pin 9
   LCD D4 pin to digital pin 4
   LCD D5 pin to digital pin 5
   LCD D6 pin to digital pin 6
   LCD D7 pin to digital pin 7
   Backlight PWM control to Pin 10
   LCD R/W pin to ground
*/
// Set the I/O pin for LCD 4-bit mode following the library assignment:
//  LiquidCrystal(rs, en, d4, d5, d6, d7).
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

int btnPIN = A0; // select the input pin for the keypad
int lcd_key     = 0;
int adc_key_in  = 0;
static int count   = 0;
int btnNow  = 0;
int btnPrev = 9;
int addCnt = 0; // value added to count
static unsigned long tmrPrev1 = 0;
static unsigned long tmrPrev2 = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

// read the buttons
int read_LCD_buttons()
{
  adc_key_in = analogRead(btnPIN);      // read the value from the sensor

  // button value's measured
  //select  = 720
  //up      = 131
  //down    = 308
  //left    = 480
  //right   = 0
  //none    = 1023
  // I add approx 50 to those values and check to see if we are close
  if (adc_key_in > 1500) return btnNONE;
  if (adc_key_in < 50)   return btnRIGHT;
  if (adc_key_in < 195)  return btnUP;
  if (adc_key_in < 380)  return btnDOWN;
  if (adc_key_in < 500)  return btnLEFT;
  if (adc_key_in < 770)  return btnSELECT;
  return btnNONE;  // when all others fail, return this...
}

void setup() {
  Serial.begin(9600);
   tmrPrev1 = millis();
  tmrPrev2 = millis();
}

void loop() {
  if ( (millis() - tmrPrev1) >= 800UL) {
    btnNow = read_LCD_buttons();
    addCnt = 1;
    process_key();
    Serial.print(count);
    Serial.print(" -- ");
    Serial.print(btnNow);
    Serial.print(" -2- ");
    Serial.println(millis() / 1000);
    tmrPrev1 = millis();
    // do something wiht this info
  }
  if ( (millis() - tmrPrev2) >= 5000UL) {
    btnNow = read_LCD_buttons();
    addCnt = 10;
    process_key();
    Serial.print(count);
    Serial.print(" -- ");
    Serial.print(btnNow);
    Serial.print(" -2- ");
    Serial.println(millis() / 1000);
    tmrPrev2 = millis();
    // do something wiht this info
  }
}

void process_key() {
  switch (btnNow) {
    case btnRIGHT:
      break;

    case btnUP:
      count += addCnt;
      break;

    case btnDOWN:
      count_ = addCnt;
      break;

    case btnLEFT:
      break;

    case btnSELECT:
      break;
   }
}

Please post the complete error message, not a paraphrased version of it.

Notice something different about this line?

count_ = addCnt;

Note the underscore after "count".

oeps

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.