Page 1 sur 1

Arduino programmation

Posté : sam. 30 mai 2015 11:51
par nicodu13
Voici mon programme,
je souhaiterais savoir si quelqu'un peut voir si il y a une erreur sur mon programme
car je souhaiterais utiliser un RTC pour enclencher un solénoïde a une heure bien precise sauf que pour insérer l'heure en question je souhaite utiliser un clavier et un écran.
Merci par avance


#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
#include <Keypad.h>

const int controlPin1 = 2;
const int controlPin2 = 3;
const int enablePin = 9;

int Motord = 5 ;
int Motorg = 6 ;

char toucheD;
char toucheU;
char toucheDM;
char toucheUM;
char key;


RTC_DS1307 RTC;

LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

void setup () {
Serial.begin(57600); //Démarrage de la communication
Wire.begin(); //Démarrage de la librairie wire.h
RTC.begin(); //Démarrage de la librairie RTClib.h

RTC.adjust(DateTime(__DATE__, "13:47:00"));

//Si RTC ne fonctionne pas
if (! RTC.isrunning()) {
Serial.println("RTC ne fonctionne pas !");

//Met à l'heure à date à laquelle le sketch est compilé
//RTC.adjust(DateTime(__DATE__, __TIME__));
}
lcd.begin(20,4); // Initialise le LCD avec 20 colonnes x 4 lignes
delay(10);

pinMode (Motord, OUTPUT);
pinMode (Motorg, OUTPUT);
}

const byte LIGNES = 4; // 4 lignes
const byte COLONNES = 3; //4 colonnes


// --- constantes des broches ---

const int C3=3; //declaration constante de broche
const int C2=4; //declaration constante de broche
const int C1=5; //declaration constante de broche
const int RS=8; //declaration constante de broche
const int E=9; //declaration constante de broche
const int D4=10; //declaration constante de broche
const int D5=11; //declaration constante de broche
const int D6=12; //declaration constante de broche
const int D7=13; //declaration constante de broche
const int L4=7; //declaration constante de broche
const int L3=A1; //declaration constante de broche
const int L2=A2; //declaration constante de broche
const int L1=A3; //declaration constante de broche

// --- Déclaration des variables globales ---

//--- Définition des touches
char touches[LIGNES][COLONNES] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};

// tableaux de lignes et colonnes
byte BrochesLignes[LIGNES] = {L1, L2, L3, L4}; //connexions utilisées pour les broches de lignes du clavier
byte BrochesColonnes[COLONNES] = {C1, C2, C3}; //connexions utilisées pour les broches de colonnes du clavier


Keypad clavier = Keypad( makeKeymap(touches), BrochesLignes, BrochesColonnes, LIGNES, COLONNES );


void loop()
{

DateTime now = RTC.now();
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(3000);

toucheD = clavier.getKey(); // lecture de la touche appuyée

if (toucheD != NO_KEY)
{ // si une touche a été frappée -- gestion de la touche appuyée
enum eEtat {
ATTENTE_ETOILE,
ATTENTE_DIZAINE,
ATTENTE_UNITE,
ATTENTE_ETOILE_M,
ATTENTE_DIZAINE_M,
ATTENTE_UNITE_M,
ATTENTE_ETOILE_F,
};
typedef enum eEtat eEtat;


eEtat etatActuel = ATTENTE_ETOILE;

key = clavier.getKey();

if ( key != NO_KEY ) {

switch(etatActuel) {

case ATTENTE_ETOILE:

if ( key == '*' ) {
etatActuel = ATTENTE_DIZAINE;
}

break;

case ATTENTE_DIZAINE:

if ( key >= '0' && key <= '2' ) {
toucheD = key;
etatActuel = ATTENTE_UNITE;
}
break;

case ATTENTE_UNITE:

if (
( key >= '0' && key <= '9' && toucheD >= '0' && toucheD <= '2' )
||
( key >= '0' && key <= '3' && toucheD == '2' )
) {
toucheU = key;
etatActuel = ATTENTE_ETOILE;
}
break;

case ATTENTE_ETOILE_M:

if ( key == '*' ) {
etatActuel = ATTENTE_DIZAINE_M;
}

break;

case ATTENTE_DIZAINE_M:

if ( key >= '0' && key < '6' ) {
toucheDM = key;
etatActuel = ATTENTE_UNITE_M;
}
break;

case ATTENTE_UNITE_M:

if ( key >= '0' && key <= '9' ) {
toucheUM = key;
etatActuel = ATTENTE_ETOILE_F;
}
break;

}
int nbD = ( (int)( toucheD - '0' ) );
int nbU = ( (int)( toucheU - '0' ) );

int nbH = ( ( nbD * 10 ) + nbU );

int nbDM = ( (int)( toucheDM - '0' ) );
int nbUM = ( (int)( toucheUM - '0' ) );

int nbM = ( ( nbDM * 10 ) + nbUM );

int sensorValue = analogRead(A0);

float voltage = sensorValue * (5.0 / 1023.0);

if (now.hour() == nbH && now.minute() == nbM) {
if (voltage >= 1.36){
delay(300);
}
else {
digitalWrite (Motord, LOW);
digitalWrite (Motorg, HIGH);
delay (3000);
digitalWrite (Motorg, LOW);
delay (1000);
digitalWrite (Motorg, LOW);
digitalWrite (Motord, HIGH);
delay (3000);
digitalWrite (Motord, LOW);
delay (1000);
}
delay(100);
}

}
}
}

Re: Arduino programmation

Posté : sam. 19 sept. 2015 10:11
par nergens
Bonjour,

Votre sujet n'a jamais reçu de réponse et nous en sommes désolés... :(

Nous espérons sincèrement vous revoir bientôt si vous avez d'autres questions et nous ferons le maximum pour vous répondre le plus rapidement et complètement possible.

A bientôt
:bonjour: