Go Down

Topic: keypad.addEventListener(keypadEvent); (Read 1 time) previous topic - next topic

Adroham

I'm confused how to fix code and also why that code which is   keypad.addEventListener(keypadEvent); is declared in this scope? someone let me know please

#include <LiquidCrystal_I2C.h>
#include <DS3231.h>
#include <Keypad.h>


const byte ROWS = 4;
const byte COLS = 3;
char keys [ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5};
byte colPins[COLS] = {4, 3, 2};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

boolean blink = false;


LiquidCrystal_I2C lcd(0x3F, 20, 4);

DS3231 rtc(SDA,SCL);
Time t;




int led1 =13;


void setup() {
  // put your setup code here, to run once:


  lcd.init();
  lcd.backlight();
  lcd.setCursor(5,2);
  lcd.print("Hello");
  delay(1000);
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print("We gotta start!");
  delay(2000);
  lcd.clear();
  lcd.setCursor(5,1);
  lcd.print("Loading.");
  delay(800);
  lcd.clear();
  lcd.setCursor(5,1);
  lcd.print("Loading...");
  delay(800);
  lcd.clear();
  lcd.setCursor(5,1);
  lcd.print("Loading.....");
  delay(800);

  lcd.noBacklight();
  delay(1000);
 
  lcd.clear();
  lcd.init();
  lcd.backlight();

  pinMode(led1,OUTPUT);
  keypad.addEventListener(keypadEvent);
  rtc.begin();
  rtc.setTime(7,59,55);
  rtc.setDate(22,9,2017); 
 
}
  void loop(){
  char key =keypad.getKey();

 
  t = rtc.getTime();
  int cur_date = t.date;
  int cur_month= t.mon; 
  int cur_year= t.year; 
  int cur_hour=t.hour;
  int cur_min=t.min;
  int cur_sec=t.sec;
  lcd.setCursor(0,0);
  lcd.print(cur_year);
  lcd.print("-");
  lcd.print(cur_month);
  lcd.print("-");
  lcd.print(cur_date);
  lcd.print("  ");


  lcd.setCursor(11,0);
  lcd.print(cur_hour);
  lcd.print(":");
  lcd.print(cur_min);
  lcd.print(":");
  lcd.println(cur_sec);

  if(cur_hour == 8 && cur_min ==00){
    lcd.setCursor(0,2);
    lcd.print("Get the alarm");
    digitalWrite(led1,HIGH);
    delay(100);
    digitalWrite(led1,LOW);
    delay(100);

  }else{
    digitalWrite(led1,HIGH);
    delay(1000);
  }
    String lcd1string= "00";
    String lcd2string= "00";
    String lcd3string= "00";
    lcd.setCursor(0,3);
    lcd.print(lcd1string);
    lcd.print(":");
    lcd.print(lcd2string);
    lcd.print(":");
    lcd.print(lcd3string);
    if(key!=NO_KEY){
    lcd.setCursor(0,1);
    lcd.print(key);
  }
  void keypadEvnet(KeypadEvnet key){
    switch (keypad.getState()){
      case PRESSED:
      case '#' : digitalWrite(ledPin,!digitalRead(ledPin));
      break;
      case '*' : digitalWrite(ledPin,!digitalRead(ledPin));
      break;
    }
    break;
    case RELEASED:
    switch (key){
      case '*':
      digitalWrite(ledPin,!digitalRead(ledPin));
      blink = false;
      break;
    }
    break;
    case HOLD:
    switch (key){
      case '*':blink = true;
      break;
    }
    break;
  }
}

johnwasser

Code: [Select]
sketch_sep22a:124: error: variable or field 'keypadEvnet' declared void
   void keypadEvnet(KeypadEvnet key) {
                    ^
sketch_sep22a:124: error: 'KeypadEvnet' was not declared in this scope
sketch_sep22a:148: error: expected '}' at end of input
 }
 ^


I think it's because you spelled "Event" wrong.  Try "KeypadEvent", not "KeypadEvnet".
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

PaulS

Quote
I'm confused how to fix code
Why do you think the improperly posted code needs fixing?

Quote
and also why that code which is   keypad.addEventListener(keypadEvent); is declared in this scope?
What scope do you think it should be "declared" in? Code is not declared. Variables are.

If you foolishly insist on putting the { on the line with the function declaration or the if statement, atleastusesomespacesoitisrecognizable.
The art of getting good answers lies in asking good questions.

Go Up