Bonjour ,
Je cale sur ce problème.
Je voudrais mettre à jour des variables objet mais qui utilise un variable globale dans ça méthode et cela ne fonctionne pas.
Concrètement j’ai besoin de récupérer l’appuie d’un bouton voici le code .
Ino:
/*
Name: reveil_matin.ino
Created: 05/12/2019 13:07:16
Author: Marycha
*/
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
#include"display_lcd.h"
#include"switch.h"
#define ADRR_LCD 0x3F
#define PIN_SWITCH_ALRM 2
#define PIN_SWICTH_BLUE 3
#define PIN_SWITCH_WHITE 4
#define PIN_SWITCH_BLACK 5
#define PIN_SWITCH_YELLOW 6
// The setup() function runs once each time the micro-controller starts
Screen Lcd(ADRR_LCD, 16, 2);
Switch switch_lever(PIN_SWITCH_ALRM);
PushButton blue_bttn(PIN_SWICTH_BLUE), yelw_bttn(PIN_SWITCH_YELLOW), wht_bttn(PIN_SWITCH_WHITE), blk_bttn(PIN_SWITCH_BLACK);
RTC_DS1307 Rtc ;
// prototype
struct NewSettingValue
{
int year;
int day;
int day_of_week;
int month;
int hours;
int min;
};
void alarm_shut_down();
NewSettingValue setting_hours(DateTime* date, PushButton* btt_blue, PushButton* btt_yel, PushButton* btt_blk);
void setup()
{
// initiaisation des objets
Lcd.init();
switch_lever.init();
blue_bttn.init();
yelw_bttn.init();
wht_bttn.init();
blk_bttn.init();
Rtc.begin();
Serial.begin(9600);
// Mise a l'heure du module rtc
Rtc.adjust(DateTime(__DATE__,__TIME__));
// interruption de l'alarme
attachInterrupt(0,alarm_shut_down,RISING);
}
void loop()
{
DateTime now = Rtc.now();
Lcd.display_home(&now, switch_lever.ctl_state());
if (wht_bttn.long_push().action)
{
setting_hours(&now);
}
}
void alarm_shut_down()
{
switch_lever.state = false;
}
NewSettingValue setting_hours(DateTime* date)
{
NewSettingValue new_value;
Lcd.clear();
while (!blk_bttn.state)
{
Serial.println(blk_bttn.long_push().action);
Lcd.display_set_hour(date->hour() + blue_bttn.long_push().increment, date->minute() + yelw_bttn.long_push().increment, date->second());
}
Lcd.clear();
}
puis le module des boutons en commençant par le .h:
#ifndef SWITCH_H_
#define SWITCH_H_
#define DELAY_PUSH 500
/*
module implemente les fonctions de chaque bouton
*/
static unsigned long PREVIOUS_MLLS_BTTN = 0;
class Switch
{
public:
Switch(int pin);
void init();
volatile bool state;
bool ctl_state();
protected:
int swicth_pin;
private:
};
class PushButton : public Switch
{
public:
PushButton(int pin);
struct Command
{
bool action = false;
int increment = 0;
};
Command long_push();
protected:
private:
};
#endif
et le .cpp
#include "switch.h"
#include "arduino.h"
Switch::Switch(int pin )
{
swicth_pin = pin;
}
void Switch::init()
{
pinMode(swicth_pin, INPUT);
}
bool Switch::ctl_state()
{
if (digitalRead(swicth_pin))
{
state = false;
}
else
{
state = true;
}
return state;
}
PushButton::PushButton(int pin) : Switch(pin)
{
}
PushButton::Command PushButton::long_push()
{
Command order;
ctl_state();
unsigned long current_millis = millis();
if (state == true && current_millis - PREVIOUS_MLLS_BTTN >= DELAY_PUSH)
{
order.action = true;
order.increment = 1;
if (current_millis - PREVIOUS_MLLS_BTTN >= DELAY_PUSH + 2000)
{
order.increment = 5;
if (current_millis - PREVIOUS_MLLS_BTTN >= DELAY_PUSH + 5000)
{
order.increment = 10;
}
}
}
else if (state == false)
{
PREVIOUS_MLLS_BTTN = current_millis;
order.action = false;
order.increment = 0;
}
return order;
}
Je pense que c’est la variable PREVIOUS_MLLS_BTTN
qui ne ce mets pas a jour du coup je pense que mets condition sont toujours fausse .
Merci
+0
-0