SetTime probleem

Arduino specifieke Software
Berichten: 63
Geregistreerd: 09 Jun 2017, 01:59
Woonplaats: Fiji

SetTime probleem

Berichtdoor Dino » 14 Jun 2017, 15:14

heb hier een code maar wil niet lopen zit vast op setTime wat doe ik hier verkeerd .
Code: Alles selecteren

#include <Wire.h>
#include <Keypad.h>
#include <Keypad_I2C.h>
#include <LiquidCrystal_I2C.h>
#include <Tone.h>
#include <Timer.h>
#define pound 14

Timer counter;
LiquidCrystal_I2C lcd(0x27,16,2);

int DefuseTimer = 0;
Tone tone1;
int oldS = 0;
int nbBoucle = 0;

const int pinWriteDefused = 2;
const int pinWriteBoom = 3;
const int pinReadDefused = 4;
const int pinReadBoom = 5;

char password[5];
int currentLength = 0;
int i = 0;
char entered[5];
int passwordLength;
int nbtry = 3;
int currentTry = nbtry;
const int Buzzer = 6;

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};


byte rowPins[ROWS] = {0,1,2,3};
byte colPins[COLS] = {4,5,6};
int adress = 0x38;
Keypad_I2C keypad = Keypad_I2C( makeKeymap(keys), rowPins, colPins, ROWS, COLS, adress );

boolean b600s = true;
boolean b300s = true;
boolean b120s = true;
boolean b60s = true;
boolean b30s = true;
boolean b10s = true;


void setup()
{
  lcd.init();
  lcd.backlight();
  lcd.begin(16,2);
  int hours, minutes, seconds;
lcd.begin(16, 2);
  Serial.begin(9600);
  tone1.begin(Buzzer);
  //pinMode(Buzzer, OUTPUT);
  //digitalWrite(Buzzer, LOW);
  char key;
  boolean cancel; 
 
  do
  {
    cancel = false;
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Time ?");
    lcd.setCursor(4,1);
    //Heures
    hours = readHours();
    if (hours == -1)
      cancel = true;
    else
      lcd.print(":");
   
    //Minutes
    if (cancel == false)
    {
      minutes = readMinutes();
      if (minutes == -1)
        cancel = true;
      else
        lcd.print(":");
    }
   
    //Secondes
    if (cancel == false)
    {
      seconds = readSeconds();
      if (seconds == -1)
        cancel = true;
    }
   
    if (cancel == false)
    {
      do
        key = keypad.waitForKey();
      while (key != '#' && key != '*');
      buttonBip(100);
      if (key == '*')
        cancel = true;
    }
   
  }
  while (cancel == true);
  delay (500);
  counter.setTime(hours, minutes, seconds);
 
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Enter Code: ");
  while ((currentLength < 1 || key != '#'))
  {
    lcd.setCursor(currentLength, 1);
    lcd.cursor();
    key = keypad.getKey();
    if (key != NO_KEY)
    {
      buttonBip(100);
      if (key != '#' && key != '*' && currentLength < 10)
      {
        lcd.print(key);
        password[currentLength] = key;
        ++currentLength;
        passwordLength = currentLength;
      }
      else if (key == '*')
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Enter Code: ");
        currentLength = 0;
        passwordLength = currentLength;
      }
    }
  }
  Serial.print("rad:bomb:planted");
  delay(500);
  lcd.clear();
  currentLength = 0;
}

void loop()
{
  timer();
  currentLength = 0;
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Code: ");
 
  boolean lec_code = true;
  char code[10];
  int i = 0;
  char key2;
   
  while (lec_code == true)
  {
    timer();
   
    key2 = keypad.getKey();
    if (key2 != NO_KEY)
      buttonBip(100);
     
    if (key2 == '#' || i >= 10)
      lec_code = false;
    else if (key2 == '*')
    {
      currentLength = 0;
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Code: ");
    }
    else                 
    if (key2 != NO_KEY && currentLength < 10)   
    {
      entered[currentLength] = key2;
      currentLength++;
      delay(100);
      lcd.noCursor();
      lcd.setCursor(currentLength + 4, 0);
      lcd.print(key2);
      lcd.setCursor(currentLength + 5, 0);
      lcd.cursor();
    }
  }
 
  boolean correct = true;
  for (int j = 0; j < currentLength; ++j)
    if (entered[j] != password[j])
      correct = false;
     
  if (correct == true && passwordLength == currentLength)
  {
    Defused();
  }
  else if (currentLength >= 1)
  {
    lcd.noCursor();
    lcd.clear();
    lcd.home();
    lcd.print("Wrong Password!");
    buttonBip(100);
    delay(200);
    buttonBip(100);
    --currentTry;
    if (currentTry == 0)
      Boom();
    lcd.setCursor(0, 1);
    lcd.print("Try : ");
    lcd.print(currentTry);
    delay(1500);
    currentLength = 0;

  } 
}

//--------------------------------- Timer --------------------------------
void timer()
{
  if (counter.seconds == 0 && counter.minutes == 10 && counter.hours == 0 && b600s == true) {Serial.print("rad:bomb:600s"); b600s = false;}
  if (counter.seconds == 0 && counter.minutes == 5 && counter.hours == 0 && b300s == true) {Serial.print("rad:bomb:300s"); b300s = false;}
  if (counter.seconds == 0 && counter.minutes == 2 && counter.hours == 0 && b120s == true) {Serial.print("rad:bomb:120s"); b120s = false;}
  if (counter.seconds == 0 && counter.minutes == 1 && counter.hours == 0 && b60s == true) {Serial.print("rad:bomb:60s"); b60s = false;}
  if (counter.seconds == 30 && counter.minutes == 0 && counter.hours == 0 && b30s == true) {Serial.print("rad:bomb:30s"); b30s = false;}
  if (counter.seconds == 10 && counter.minutes == 0 && counter.hours == 0 && b10s == true) {Serial.print("rad:bomb:10s"); b10s = false;}
 
  ++nbBoucle;
  if (((counter.seconds > 10 && counter.minutes < 1 && counter.hours < 1) || (counter.minutes >= 1 || counter.hours >= 1)) && oldS != counter.seconds)
  {
    oldS = counter.seconds;
    timeBip(100);
  }
  else if (counter.seconds <= 10 && counter.seconds > 5 && counter.minutes < 1 && counter.hours < 1 && nbBoucle >= 15)
  {
    nbBoucle = 0;
    timeBip(100);
  }
  else if (counter.seconds <= 5 && counter.seconds > 3 && counter.minutes < 1 && counter.hours < 1 && nbBoucle >= 10)
  {
    nbBoucle = 0;
    timeBip(100);
  }
  else if (counter.seconds <= 3 && counter.minutes < 1 && counter.hours < 1 && nbBoucle >= 5)
  {
    nbBoucle = 0;
    timeBip(100);
  }
 
  refreshTimeLcd();
 
  if (counter.decrement(millis()))
  {
    Boom ();
  }
  readPort();
  lcd.noCursor();
  delay(10); // waits for a second
  delay(10); // waits for a second
}

//--------------------------------- LCD --------------------------------
void refreshTimeLcd()
{
  lcd.setCursor (0,1); // sets cursor to 2nd line
  lcd.print ("Timer:");
  if (counter.hours >= 10)
  {
    lcd.setCursor (7,1);
    lcd.print (counter.hours);
  }
  if (counter.hours < 10)
  {
    lcd.setCursor (7,1);
    lcd.print ("0");
    lcd.setCursor (8,1);
    lcd.print (counter.hours);
  }

  lcd.print (":");

  if (counter.minutes >= 10)
  {
    lcd.setCursor (10,1);
    lcd.print (counter.minutes);
  }
  if (counter.minutes < 10)
  {
    lcd.setCursor (10,1);
    lcd.print ("0");
    lcd.setCursor (11,1);
    lcd.print (counter.minutes);
  }
   
  lcd.print (":");

  if (counter.seconds >= 10)
  {
    lcd.setCursor (13,1);
    lcd.print (counter.seconds);
  }
  if (counter.seconds < 10)
  {
    lcd.setCursor (13,1);
    lcd.print ("0");
    lcd.setCursor (14,1);
    lcd.print (counter.seconds);
  }
}

//--------------------------------- Heures --------------------------------
int readHours ()
{
  char key;
  char hour[3];
  int hours;
  for (int i=0; i<2; ++i)
  {
    do
    {
      key = keypad.waitForKey();
      if (key != NO_KEY)
        buttonBip(100);
    }
    while (key == NO_KEY || key == '#');

    if (key == '*')
      return -1;
     
    hour[i] = key;
    lcd.print(key);
  }
  hour[2] = '\0';
  hours = atoi(hour);
  return hours;
}

//--------------------------------- Minutes --------------------------------
int readMinutes ()
{
  char stTemp[2];
  char key;
  char minute[3];
  int minutes;
  for (int i=0; i<2; ++i)
  {
    do
    {
      key = keypad.waitForKey();
      if (key != NO_KEY)
        buttonBip(100);
      if (key == '*')
        return -1;
      sprintf(stTemp,"%c",key);
    }
    while (key == NO_KEY || key == '*' || key == '#' || ((atoi(stTemp)) >= 6 && i == 0));
    minute[i] = key;
    lcd.print(key);
  }
  minute[2] = '\0';
  minutes = atoi(minute);
  return minutes;
}

//--------------------------------- Secondes --------------------------------
int readSeconds ()
{
  char stTemp[2];
  char key;
  char second[3];
  int seconds;
  for (int i=0; i<2; ++i)
  {
    do
    {
      key = keypad.waitForKey();
      if (key != NO_KEY)
        buttonBip(100);
      if (key == '*')
        return -1;
      sprintf(stTemp,"%c",key);
    }
    while (key == NO_KEY || key == '*' || key == '#' || (atoi(stTemp) >= 6 && i == 0));
    second[i] = key;
    lcd.print(key);
  }
  second[2] = '\0';
  seconds = atoi(second);
  return seconds;
}

//--------------------------------- Boom -------------------------------------
void Boom ()
{
  Serial.print("rad:bomb:explosed");
  pinMode(pinWriteBoom, OUTPUT);
  digitalWrite(pinWriteBoom, HIGH);
  lcd.noCursor();
  lcd.clear();
  lcd.home();
  lcd.print("The Bomb Has ");
  lcd.setCursor (0,1);
  lcd.print("Exploded!");
  tone1.play(NOTE_F2, 3000);
  delay(8000);
  digitalWrite(3, LOW);
  while (1)
    delay(100000);
}

//--------------------------------- Defused ----------------------------------
void Defused ()
{
  Serial.print("rad:bomb:defused");
  pinMode(pinWriteDefused, OUTPUT);
  digitalWrite(pinWriteDefused, HIGH);
  lcd.noCursor();
  lcd.clear();
  lcd.home();
  lcd.print("Bomb Defused");
  refreshTimeLcd();
  buttonBip(200);
  delay(300);
  buttonBip(200);
  delay(300);
  buttonBip(200);
  currentLength = 0;
  while (1)
    delay(1000000);
}

//--------------------------------- readPort ----------------------------------
void readPort()
{
  pinMode(pinReadDefused, INPUT);
  pinMode(pinReadBoom, INPUT);
  byte defused = digitalRead(pinReadDefused);
  byte boom = digitalRead(pinReadBoom);
  if (defused == HIGH)
    Defused();
  if (boom == HIGH)
    Boom();
}

//---------------------------------- timeBip ---------------------------------
void timeBip (int mills)
{
  tone1.play(NOTE_F7, mills);
}

//---------------------------------- buttonBip ---------------------------------
void buttonBip (int mills)
{
  tone1.play(NOTE_A7, mills);
}

Advertisement

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: SetTime probleem

Berichtdoor nicoverduin » 14 Jun 2017, 16:03

Onduidelijk zijn waar je het over hebt......
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 63
Geregistreerd: 09 Jun 2017, 01:59
Woonplaats: Fiji

Re: SetTime probleem

Berichtdoor Dino » 16 Jun 2017, 18:46

counter.setTime(hours, minutes, seconds);
deze regel geeft fout
exit status 1
'class Timer' has no member named 'setTime'

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: SetTime probleem

Berichtdoor nicoverduin » 16 Jun 2017, 19:12

Kennelijk heeft de xlass timer deze method() of funxtie() ( hoe je het ook noemen wilt). Oorzaak is of deze method staat niet in timer.h en timer.cpp. Of je hebt een type fout gemaakt of (als je dit ergens vandaan hebt gekopieerd) de auteur heeft een andere library gebruikt
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Terug naar Arduino software

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 16 gasten