| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- #include "My_Eeprom.h"
- #include <EEPROM.h>
- #include "Testeur.h"
- #include <Wire.h>
- newPin tabPin[NBPIN];
- int pinTECBA = 22;
- unsigned long valRandom;
- void setup() {
- Serial.begin(115200);
- Wire.begin();
- initTabPin();
-
- pinMode(pinTECBA,OUTPUT);
- valRandom = (long)1000*60*MINUTE/DELAYLOOP;
- randomSeed(analogRead(0));
- }
- void loop() {
- for(int i = 0; i<NBPIN;i++){
- toogle(i);
- }
- NiveauBas();//TODO niveau bas tech
-
- if (Serial.available() > 0) {
- int incomingByte = Serial.read();
- if(incomingByte=='A'){
- AfficheEEprom();
- }
- if(incomingByte=='E'){
- erase();
- }
- if(incomingByte=='I'){
- instantane();
- }
- }
- delay(DELAYLOOP);
- }
- /* pinBRAS1, pinBRAS2, pinOSMOL, pinCHAUF, pinECUME, pinREMON, pinLUMIE
- pinTECBA, pinTECHA, pinCUVAU, pinRESBA */
- void initTabPin(void){
- for(int i = 0; i<NBPIN;i++){
- tabPin[i].num=i*2+23;
- pinMode(tabPin[i].num,INPUT);
- tabPin[i].last = digitalRead(tabPin[i].num);
- }
- }
- uint8_t toogle(uint8_t pin){
- uint8_t val = digitalRead(tabPin[pin].num);
- if(tabPin[pin].last!=val){
- Serial.println(pin);
- tabPin[pin].last = val;
- switch(pin){
- case 0:
- fc_BRAS1(val);
- break;
- case 1:
- fc_BRAS2(val);
- break;
- case 2:
- fc_OSMO(val);
- break;
- case 3:
- fc_CHAUFF(val);
- break;
- case 4:
- fc_ECUM(val);
- break;
- case 5:
- fc_REMO(val);
- break;
- case 6:
- fc_LUMI(val);
- break;
- case 7:
- fc_TECBA(val);
- break;
- case 8:
- fc_TECHA(val);
- break;
- case 9:
- fc_CUVAU(val);
- break;
- case 10:
- fc_RESBA(val);
- break;
- }
- return 1;
- }
- return 0;
- }
- void NiveauBas(void){
- unsigned long tempsActuel = millis();
-
- // si le signal est actuellement haut, l'éteindre lorsque le temps imparti est écoulé
- if (digitalRead(pinTECBA) == HIGH && tempsActuel - tempsSignal >= intervalleMinimum) {
- digitalWrite(pinTECBA, LOW);
- }
- // si le signal est actuellement bas, attendre un temps aléatoire avant de le mettre en marche
- if (digitalRead(pinTECBA) == LOW && tempsActuel - tempsPrecedent >= tempsAttente) {
- tempsSignal = tempsActuel;
- digitalWrite(pinTECBA, HIGH);
- tempsAttente = random(intervalleAttenteMinimum, intervalleAttenteMaximum + 1); // temps d'attente aléatoire avant le prochain signal
- }
- // si le signal a été éteint, attendre 1 seconde avant de recommencer
- if (digitalRead(pinTECBA) == LOW && tempsActuel - tempsPrecedent >= 1000) {
- tempsPrecedent = tempsActuel;
- }
- // si le signal a été allumé, attendre un temps aléatoire avant de l'éteindre
- if (digitalRead(pinTECBA) == HIGH && tempsActuel - tempsSignal < intervalleMinimum) {
- tempsPrecedent = tempsActuel;
- }
- // si le signal a été allumé pendant le temps imparti, attendre un temps aléatoire avant de recommencer
- if (digitalRead(pinTECBA) == HIGH && tempsActuel - tempsSignal >= intervalleMinimum) {
- digitalWrite(pinTECBA, LOW);
- tempsPrecedent = tempsActuel;
- nbSignaux++;
- if (nbSignaux >= 5) {
- while (true) {} // arrêter le programme
- }
- tempsAttente = random(intervalleAttenteMinimum, intervalleAttenteMaximum + 1); // temps d'attente aléatoire avant le prochain signal
- }
- }
- void fc_BRAS1(int val) {
- if(val){
- Enregistre(BR1ON);
- }
- else{
- Enregistre(BR1OF);
- }
- }
- void fc_BRAS2(int val) {
- if(val){
- Enregistre(BR2ON);
- }
- else{
- Enregistre(BR2OF);
- }
- }
- void fc_OSMO(int val) {
- if(val){
- Enregistre(OSMON);
- }
- else{
- Enregistre(OSMOF);
- }
- }
- void fc_CHAUFF(int val) {
- if(val){
- Enregistre(CHAON);
- }
- else{
- Enregistre(CHAOF);
- }
- }
- void fc_ECUM(int val) {
- if(val){
- Enregistre(ECUON);
- }
- else{
- Enregistre(ECUOF);
- }
- }
- void fc_REMO(int val) {
- if(val){
- Enregistre(REMON);
- }
- else{
- Enregistre(REMOF);
- }
- }
- void fc_LUMI(int val) {
- if(val){
- Enregistre(LUMON);
- }
- else{
- Enregistre(LUMOF);
- }
- }
- void fc_TECBA(int val) {
- if(val){
- Enregistre(TEBON);
- }
- else{
- Enregistre(TEBOF);
- }
- }
- void fc_TECHA(int val) {
- if(val){
- Enregistre(TEHON);
- }
- else{
- Enregistre(TEHOF);
- }
- }
- void fc_CUVAU(int val) {
- if(val){
- Enregistre(CUHON);
- }
- else{
- Enregistre(CUHOF);
- }
- }
- void fc_RESBA(int val) {
- if(val){
- Enregistre(REBON);
- }
- else{
- Enregistre(REBOF);
- }
- }
|