Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_WS2801.h>
- #include <LiquidCrystal_PCF8574.h>
- ///////////////////////////////////////
- #include <SPI.h> // librairie pour la communication SPI
- #include <MFRC522.h> // librairie pour les lecteurs RFID
- #include <Wire.h> // librairie pour la connection i2c
- LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line display
- //librairie leds
- #include <Adafruit_NeoPixel.h>
- #ifdef __AVR__
- #include <avr/power.h>
- #endif
- #define PIN 8
- // READERS ////////////////////////////////////////////////////////////////////////////////
- #define RST_PIN 9
- #define SS_1_PIN A0
- #define SS_2_PIN A1
- #define SS_3_PIN A2
- #define SS_4_PIN A3
- #define SS_5_PIN A4
- #define SS_6_PIN 4
- #define SS_7_PIN 5
- #define SS_8_PIN 6
- #define NR_OF_READERS 8
- byte ssPins[] = {SS_1_PIN, SS_2_PIN, SS_3_PIN, SS_4_PIN, SS_5_PIN, SS_6_PIN, SS_7_PIN, SS_8_PIN};
- //byte ssPins[] = {SS_1_PIN};
- MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.
- byte nuidPICC[3];
- //
- //BOUTONS ////////////////////////////////////////////////////////////////////////////////
- const int boutonPlus = A5;
- const int boutonMoins = 10;
- int boutonTarifHaut = 11;
- int boutonTarifMoy = 12;
- int boutonTarifBas = 13;
- int compteurMenu = 1;
- int puiss_old = 0;
- int puiss_sous_old = 0;
- float conso_max = 8000;
- float conso_annee = 11000;
- //
- //VARIABLES COMPTEUR ////////////////////////////////////////////////////////////////////////////////
- int PUISSANCE_APP[14] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- int PUISSANCE_ANNEE[14] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- int TOT_PUISSANCE_APP = 0;
- int PUISSANCE_MAX = 0;
- int P_SOUSCRITE = 0;
- int PUISSANCE_COUP = 0;
- int P_CONSOMMEE = 0;
- //
- //BANDE LEDS////////////////////////////////////////////////////////////////////////////////
- //Adafruit_NeoPixel strip = Adafruit_NeoPixel(13, PIN, NEO_GRB + NEO_KHZ800);
- int dataPin = 2;
- int clockPin = 3;
- // Set the first variable to the NUMBER of pixels. 25 = 25 pixels in a row
- Adafruit_WS2801 strip = Adafruit_WS2801(12, dataPin, clockPin);
- int dump_byte_array(byte *buffer, byte bufferSize) {
- for (byte i = 0; i < bufferSize; i++) {
- Serial.print(buffer[i] < 0x10 ? " 0" : " ");
- Serial.print(buffer[i], HEX);
- int tot = +buffer[i];
- return tot;
- }
- }
- void menu() {
- if (compteurMenu == 1) {
- lcd.clear();
- lcd.setCursor(8, 1) ;
- lcd.print("BASE") ;
- lcd.setCursor(3, 2) ;
- lcd.print("NOM DU CONTRAT") ;
- }
- if (compteurMenu == 2) {
- lcd.clear();
- lcd.setCursor(4, 1) ;
- lcd.print(P_CONSOMMEE) ;
- lcd.setCursor(10, 1) ;
- lcd.print("KWH") ;
- lcd.setCursor(8, 2) ;
- lcd.print("BASE") ;
- }
- if (compteurMenu == 3) {
- lcd.clear();
- lcd.setCursor(4, 1) ;
- lcd.print(TOT_PUISSANCE_APP) ;
- lcd.setCursor(10, 1) ;
- lcd.print(" VA") ;
- lcd.setCursor(4, 2) ;
- lcd.print("PUISSANCE APP") ;
- }
- if (compteurMenu == 4) {
- lcd.clear();
- lcd.setCursor(8, 1) ;
- lcd.print("0 VA") ;
- lcd.setCursor(4, 2) ;
- lcd.print("PUISSANCE MAX") ;
- }
- if (compteurMenu == 5) {
- lcd.clear();
- lcd.setCursor(8, 1) ;
- lcd.print(P_SOUSCRITE) ;
- lcd.setCursor(10, 1) ;
- lcd.print("KVA") ;
- lcd.setCursor(5, 2) ;
- lcd.print("P SOUSCRITE") ;
- }
- if (compteurMenu == 6) {
- lcd.clear();
- lcd.setCursor(7, 1) ;
- lcd.print(P_SOUSCRITE*1000) ;
- lcd.setCursor(12, 1) ;
- lcd.print("VA") ;
- lcd.setCursor(3, 2) ;
- lcd.print("PUISSANCE COUP") ;
- }
- if (compteurMenu == 7) {
- lcd.clear();
- lcd.setCursor(5, 1) ;
- lcd.print("00000000000") ;
- lcd.setCursor(4, 2) ;
- lcd.print("NUMERO DE PRM") ;
- }
- if (compteurMenu == 8) {
- lcd.clear();
- lcd.setCursor(6, 1) ;
- lcd.print("16:20:15") ;
- lcd.setCursor(3, 2) ;
- lcd.print("HEURE COURANTE") ;
- }
- if (compteurMenu == 9) {
- lcd.clear();
- lcd.setCursor(6, 1) ;
- lcd.print("19/05/15") ;
- lcd.setCursor(4, 2) ;
- lcd.print("DATE COURANTE") ;
- }
- if (compteurMenu == 10) {
- lcd.clear();
- lcd.setCursor(7, 1) ;
- lcd.print("OUVERT") ;
- lcd.setCursor(5, 2) ;
- lcd.print("CONTACT SEC") ;
- }
- if (compteurMenu == 11) {
- lcd.clear();
- lcd.setCursor(5, 1) ;
- lcd.print("HISTORIQUE") ;
- lcd.setCursor(6, 2) ;
- lcd.print("MODE TIC") ;
- }
- if (compteurMenu == 12) {
- lcd.clear();
- lcd.setCursor(8, 1) ;
- lcd.print("0 KWH") ;
- lcd.setCursor(4, 2) ;
- lcd.print("INDEX DISTRIB") ;
- }
- if (compteurMenu == 13) {
- lcd.clear();
- lcd.setCursor(4, 1) ;
- lcd.print("012345678912") ;
- lcd.setCursor(4, 2) ;
- lcd.print("NUMERO SERIE") ;
- }
- if (compteurMenu == 14) {
- lcd.clear();
- lcd.setCursor(8, 1) ;
- lcd.print("0 KWH") ;
- lcd.setCursor(6, 2) ;
- lcd.print("INDEX MID") ;
- }
- if (compteurMenu == 15) {
- lcd.clear();
- lcd.setCursor(8, 1) ;
- lcd.print("0 KWH") ;
- lcd.setCursor(3, 2) ;
- lcd.print("INDEX INJECTION") ;
- }
- if (compteurMenu == 16) {
- lcd.clear();
- lcd.setCursor(8, 1) ;
- lcd.print("0000") ;
- lcd.setCursor(3, 2) ;
- lcd.print("REGISTRE ERREUR") ;
- }
- if (compteurMenu == 17) {
- lcd.clear();
- lcd.setCursor(6, 1) ;
- lcd.print("F2208938") ;
- lcd.setCursor(4, 2) ;
- lcd.print("CHECKSUM MID") ;
- }
- if (compteurMenu == 18) {
- lcd.clear();
- lcd.setCursor(3, 2) ;
- lcd.print("PAS DE MESSAGE");
- }
- }
- int printDec(byte *buffer, byte bufferSize) {
- int tot;
- for (byte i = 0; i < bufferSize; i++) {
- // Serial.print(buffer[i] < 0x10 ? " 0" : " ");
- tot = tot + buffer[i];
- //Serial.print(buffer[i], DEC);
- }
- return tot;
- }
- void carte_pose(uint32_t c, uint8_t wait) {
- for (uint16_t i = 0; i < 8; i++) {
- strip.setPixelColor(i, c);
- strip.show();
- delay(wait);
- }
- }
- void chgt_contrat(uint32_t c, uint8_t wait) {
- for (int i = 12; i >= 0; i--) {
- strip.setPixelColor(i, c);
- strip.show();
- delay(wait);
- }
- }
- void petage_plombs(uint32_t c, uint8_t wait) {
- lcd.clear();
- lcd.setCursor(8, 2) ;
- lcd.print("PANNE");
- for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
- for (int q = 0; q < 3; q++) {
- for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
- strip.setPixelColor(i + q, c); //turn every third pixel on
- }
- strip.show();
- delay(wait);
- for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
- strip.setPixelColor(i + q, 0); //turn every third pixel off
- }
- }
- }
- }
- // Create a 24 bit color value from R,G,B
- uint32_t Color(byte r, byte g, byte b)
- {
- uint32_t c;
- c = r;
- c <<= 8;
- c |= g;
- c <<= 8;
- c |= b;
- return c;
- }
- //
- void setup() {
- Serial.begin(9600); // Initialize serial communications with the PC
- SPI.begin(); // Init SPI bus
- pinMode(boutonPlus, INPUT_PULLUP);
- pinMode(boutonMoins, INPUT_PULLUP);
- pinMode(boutonTarifHaut, INPUT_PULLUP);
- pinMode(boutonTarifMoy, INPUT_PULLUP);
- pinMode(boutonTarifBas, INPUT_PULLUP);
- /*for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
- mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
- //"delay(80);
- //mfrc522[reader].PCD_SetRegisterBitMask(mfrc522[reader].RFCfgReg, (0x07<<4));
- }*/
- lcd.begin(20, 4); // initialize the lcd
- //lcd.cursor_on() ;
- //lcd.blink_on() ;
- lcd.setBacklight(255);
- lcd.setCursor(0, 0) ;
- lcd.print("READY !") ;
- strip.begin();
- strip.show(); // Initialize all pixels to 'off'
- menu();
- Serial.println("ready");
- }
- /////////////////////////////////////////////////////////////////////////////////
- void loop() {
- int newcard;
- puiss_old = TOT_PUISSANCE_APP;
- TOT_PUISSANCE_APP = conso_max * 0.08;
- P_CONSOMMEE = conso_annee * 0.08;
- for (int i = 0; i < 14; i++) {
- PUISSANCE_APP[i] = 0;
- PUISSANCE_ANNEE[i]=0;
- }
- puiss_sous_old = P_SOUSCRITE;
- for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
- if (digitalRead(boutonTarifHaut) == LOW) {
- Serial.print("P_SOUSCRITE = 9");
- P_SOUSCRITE = 9;
- }
- if (digitalRead(boutonTarifMoy) == LOW) {
- Serial.print("P_SOUSCRITE = 6");
- P_SOUSCRITE = 6;
- }
- if (digitalRead(boutonTarifBas) == LOW) {
- Serial.print("P_SOUSCRITE = 3");
- P_SOUSCRITE = 3;
- }
- if (digitalRead(boutonPlus) == LOW) {
- compteurMenu = compteurMenu + 1;
- Serial.print("Plus");
- delay(50);
- }
- if (digitalRead(boutonMoins) == LOW) {
- compteurMenu = compteurMenu - 1;
- Serial.print("Moins");
- delay(50);
- }
- if (compteurMenu == 19) compteurMenu = 1;
- if (compteurMenu == 0) compteurMenu = 18;
- mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
- newcard = mfrc522[reader].PICC_IsNewCardPresent();
- if (newcard && mfrc522[reader].PICC_ReadCardSerial()) {
- byte val_card = printDec(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
- Serial.print("valeur carte : ");
- Serial.print(val_card);
- switch (val_card) {
- case 250: //chauffage electrique
- PUISSANCE_APP[0] = conso_max * 0.41;
- PUISSANCE_ANNEE[0] = conso_annee * 0.41;
- break;
- case 109: //eau chaude
- PUISSANCE_APP[1] = conso_max * 0.18;
- PUISSANCE_ANNEE[1] = conso_annee * 0.18;
- break;
- case 229: //lumiere
- PUISSANCE_APP[2] = conso_max * 0.03;
- PUISSANCE_ANNEE[2] = conso_annee * 0.03;
- break;
- case 10: // froid
- PUISSANCE_APP[3] = conso_max * 0.06;
- PUISSANCE_ANNEE[3] = conso_annee * 0.06;
- break;
- case 100: //loisirs
- PUISSANCE_APP[4] = conso_max * 0.11;
- PUISSANCE_ANNEE[4] = conso_annee * 0.11;
- break;
- case 88: //electro-menager
- PUISSANCE_APP[5] = conso_max * 0.05;
- PUISSANCE_ANNEE[5] = conso_annee * 0.05;
- break;
- case 86: //cuisson
- PUISSANCE_APP[6] = conso_max * 0.08;
- PUISSANCE_ANNEE[6] = conso_annee * 0.08;
- break;
- case 148: //chauffage eco -10%
- PUISSANCE_APP[7] = (conso_max * 0.41) - (conso_max * 0.41) * 0.2;
- PUISSANCE_ANNEE[7] = (conso_annee * 0.41) - (conso_annee * 0.41) * 0.1;
- break;
- case 131: //eau chaude eco -40%
- PUISSANCE_APP[8] = (conso_max * 0.18) - (conso_max * 0.18) * 0.4;
- PUISSANCE_ANNEE[8] = (conso_annee * 0.18) - (conso_annee * 0.18) * 0.4;
- break;
- case 130: //cuisson eco -30%
- PUISSANCE_APP[9] = (conso_max * 0.08) - (conso_max * 0.08) * 0.3;
- PUISSANCE_ANNEE[9] = (conso_annee * 0.08) - (conso_annee * 0.08) * 0.3;
- break;
- case 239: //lumiere eco -20%
- PUISSANCE_APP[10] = (conso_max * 0.03) - (conso_max * 0.03) * 0.2;
- PUISSANCE_ANNEE[10] = (conso_annee * 0.03) - (conso_annee * 0.03) * 0.2;
- break;
- case 168: //electro-menager eco -20%
- PUISSANCE_APP[11] = (conso_max * 0.05) - (conso_max * 0.05) * 0.2;
- PUISSANCE_ANNEE[11] = (conso_annee * 0.05) - (conso_annee * 0.05) * 0.2;
- break;
- case 127: //loisirs eco -40%
- PUISSANCE_APP[12] = (conso_max * 0.11) - (conso_max * 0.11) * 0.4;
- PUISSANCE_ANNEE[12] = (conso_annee * 0.11) - (conso_annee * 0.11) * 0.4;
- break;
- case 146: //froid eco -20%
- PUISSANCE_APP[13] = (conso_max * 0.06) - (conso_max * 0.06) * 0.2;
- PUISSANCE_ANNEE[13] = (conso_annee * 0.06) - (conso_annee * 0.06) * 0.2;
- break;
- }
- }
- //colorWipe(Color(63, 0, 0), 50);
- }
- for (int i = 0 ; i < 14 ; i++)
- {
- TOT_PUISSANCE_APP = TOT_PUISSANCE_APP + PUISSANCE_APP[i] ;
- P_CONSOMMEE = P_CONSOMMEE + PUISSANCE_ANNEE[i] ;
- }
- Serial.print("puissance tot : ");
- Serial.println(TOT_PUISSANCE_APP);
- if (puiss_old != TOT_PUISSANCE_APP) {
- carte_pose(Color(40, 0, 0), 50);
- carte_pose(Color(0, 0, 0), 50);
- }
- if ( puiss_sous_old != P_SOUSCRITE) {
- chgt_contrat(Color(0, 0, 40), 80);
- chgt_contrat(Color(0, 0, 0), 80);
- }
- if (TOT_PUISSANCE_APP > P_SOUSCRITE*1000) {
- petage_plombs(Color(0, 40, 0), 30);
- }
- menu();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement