Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "EmonLib.h"
- #include <Arduino.h>
- #include <U8g2lib.h>
- #include <SPI.h>
- #include <Wire.h>
- #define RELE1_PIN 8
- #define RELE2_PIN 9
- #define RELE3_PIN 10
- #define RELE4_PIN 11
- // display
- U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
- float proudy[4] = {0,0,0,0};
- // LED warning light parameters setting
- float nocurrent = 0.1;
- float lowcurrent = 0.12;
- float highcurrent = 0.20;
- // Include Emon Library
- EnergyMonitor emonitors[4];
- void setup()
- {
- Serial.begin(9600);
- while (!Serial){
- }
- Serial.println("SW VERZE 1.0");
- u8g2.begin();
- pinMode(RELE1_PIN, OUTPUT); // red
- pinMode(RELE2_PIN, OUTPUT); //orange
- pinMode(RELE3_PIN, OUTPUT); //green
- pinMode(RELE4_PIN, OUTPUT); //buzzer
- for(int n=0; n<4; n++){
- emonitors[n].current(n+A0,30); // Current: input pin, calibration.
- }
- }
- void loop(){
- for(int n=0; n<4; n++){
- proudy[n] = emonitors[n].calcIrms(1674); // Calculate Irms only (1674... n/50*5580.. orig 1480)
- }
- String jsonData = "{\"I1\":";
- jsonData += proudy[0];
- jsonData += ",\"I2\":";
- jsonData += proudy[1];
- jsonData += ",\"I3\":";
- jsonData += proudy[2];
- jsonData += ",\"I4\":";
- jsonData += proudy[3];
- jsonData += "}";
- Serial.println(jsonData);
- // u8g2.clearBuffer(); // clear the internal memory
- // u8g2.setFont(u8g2_font_logisoso28_tr); // choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
- // u8g2.drawStr(8,29,"Irms="); // write something to the internal memory
- // u8g2.sendBuffer(); // transfer internal memory to the display
- //delay(1000);
- for(int n=0; n<4; n++){
- u8g2.clearBuffer(); // clear the internal memory
- u8g2.setFont(u8g2_font_logisoso22_tr); // choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
- u8g2.setCursor(8, 29);
- u8g2.print("K");
- u8g2.print(n+1);
- u8g2.print(":");
- u8g2.print(proudy[n]);
- u8g2.print(" A");
- u8g2.sendBuffer();
- delay (1000);
- }
- // LED warning light control
- if ((proudy[0] < nocurrent) || (proudy[1] < nocurrent) || (proudy[2] < nocurrent) || (proudy[3] < nocurrent)){
- NastavitVystupy(0,1,0,0);
- }
- if ((lowcurrent > proudy[0] < highcurrent) || (lowcurrent > proudy[1] < highcurrent) || (lowcurrent > proudy[2] < highcurrent) || (lowcurrent > proudy[3] < highcurrent)){
- NastavitVystupy(0,0,1,1);
- }
- if ((proudy[0] > highcurrent) || (proudy[1] > highcurrent) || (proudy[2] > highcurrent) || (proudy[3] > highcurrent)){
- NastavitVystupy(1,0,0,0);
- }
- //delay(100);
- }
- void NastavitVystupy(bool Out1, bool Out2, bool Out3, bool Out4){
- digitalWrite(RELE1_PIN, Out1);
- digitalWrite(RELE2_PIN, Out2);
- digitalWrite(RELE3_PIN, Out3);
- digitalWrite(RELE4_PIN, Out4);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement