1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#define interruptPin 2 // Pin de l'interrupt
volatile boolean mesureEnCours = false; // Volatile pour les variables traitées en interrupt
volatile boolean mesureNouvelle = false;
volatile unsigned long tempoDepart = millis();
volatile unsigned long topSyncMilliSec = millis();
volatile unsigned long departMesure = millis();
volatile unsigned long departbit_Importante = millis();
const unsigned int topSyncMinimum = 800;
#define led_bit 12
#define ledSeconde 13
int compteurSeconde = 0;
int infoMinute = 0;
int infoheure = 0;
int infoJourDuMois = 0;
int infoJourDeLaSemaine = 0;
int infoAnnee = 0;
void setup()
{
Serial.begin (115200);
pinMode(interruptPin, INPUT_PULLUP);
pinMode(ledSeconde, OUTPUT);
digitalWrite(ledSeconde, LOW);
pinMode(led_bit, OUTPUT);
digitalWrite(led_bit, LOW);
attachInterrupt(digitalPinToInterrupt(interruptPin), impulsion_Interruption, CHANGE); //interruption pour rechercher le top syncrho du debut de la pemière seconde
}
void loop()
{
if (mesureNouvelle == true)
{
mesureNouvelle = false;
topSyncAction();
}
calibrage_Seconde();
lecture_Seconde_Importante();
lecture_Bit_Importante();
}
void impulsion_Interruption()
{
if (digitalRead(interruptPin) == LOW && !mesureEnCours)
{
tempoDepart = millis();
mesureEnCours = true;
}
if (digitalRead(interruptPin) == HIGH && mesureEnCours)
{
topSyncMilliSec = millis() - tempoDepart;
mesureEnCours = false;
mesureNouvelle = true;
}
}
void topSyncAction()
{
if (topSyncMilliSec >= topSyncMinimum)
{
departMesure = micros();
digitalWrite (ledSeconde, HIGH);
compteurSeconde = 0;
}
}
void calibrage_Seconde()
{
if (micros() - departMesure >= 140000 )
{
digitalWrite(ledSeconde, LOW);
if (micros() - departMesure >= 999550)
{
digitalWrite(ledSeconde, HIGH);
departMesure = micros();
departbit_Importante = millis();
compteurSeconde++;
}
}
}
void lecture_Seconde_Importante()
{
//Serial.println (compteur);
if ( digitalRead (ledSeconde) == HIGH && digitalRead (interruptPin) == HIGH &&(compteurSeconde >= 20 && compteurSeconde <= 58))
{
digitalWrite (led_bit , HIGH);
departbit_Importante = millis();
//Serial.println (compteurSeconde);
}
}
void lecture_Bit_Importante()
{
if( millis()- departbit_Importante >= 25)
{
digitalWrite (led_bit, LOW);
}
} |
Partager