Sari la conținut
ELFORUM - Forumul electronistilor

Ceas RGB WIFI


Kreator

Postări Recomandate

Daca tot am avut ceva timp liber de sarbatorile pascale, am facut un upgrade la ceasul de aici , in sensul ca display-ul este un panel RGB cu WS2812B  ca acesta comandat de un Wemos D1 mini. Schema e mai jos (desenata cum e moda acum :scarpin)

Culoarea si intensitatea luminoasa a display-ului se schimba prin cele 4 slidere, iar ora si minutul prin modificarea casetelor corespunzatoare. Prin combinatia celor trei slidere care comanda culorile se obtine o paleta cromatica destul de variata.

Tranzitia de la ora la temperatura si invers se face prin efect de scroll.

Valorile corespunzatoare culorilor RGB si intensitatii luminoase sunt salvate in memoria AT24C32 si incarcate automat la pornire.

 

914262690_RGBClockWiFi.thumb.jpg.0d3cad936efa3ce813fd0ea9110400da.jpg

 

Screenshot.thumb.jpg.cdbed5661fa77054d7ab357b6acd903c.jpg

389774954_20220410_164928(1).thumb.jpg.d3c2d84fb58c59d38d491792084ee142.jpg

 

Sketch-ul folosit e urmatorul, nu dati cu parul daca nu e optimizat si uneori e redundant, nu sunt programator, nici macar cu studii de electronica dar orice observatii constructive sunt binevenite.

Doritorii pot modifica Sketch-ul asfel incat culorile sa se schimbe automat, efect de curcubeu, sau alte efecte dorite.

 


#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <Wire.h>
#include <Adafruit_NeoPixel.h>
#include <OneWire.h>
#include <DallasTemperature.h>


// Pinul conectat la DS18b20
#define  oneWireBus D6

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(oneWireBus);

// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer;

// Pinul conectat INPUT Data display
#define LED_PIN D7

// Nr de leduri al display-ului
#define LED_COUNT 256

// Intensitatea, 0 {min) to 255 {max)
// #define BRIGHTNESS 5 // Set BRIGHTNESS to about 1/5 {max = 255)

// DS3231_I2C_ADDRESS
#define DS3231_I2C_ADDRESS 0x68
#define EEPROM_I2C_ADDRESS 0x57
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

// Replace with your network credentials
const char* ssid = "*********"; //reteaua WiFi la care se conecteaza
const char* password = "********"; // parola pt conectare la retea


String sliderValue1 = "128"; // valoare initiala pt slider1
String sliderValue2 = "128"; // valoare initiala pt slider2
String sliderValue3 = "128"; // valoare initiala pt slider3
String sliderValue4 = "5";   // valoare initiala pt slider4

String ora_new = "20";       // valoare initiala pt ora_new
String minut_new = "05";     // valoare initiala pt minut_new
String ora_change = "0";     // valoare initiala pt ora_change (daca se schimba ora trece in 1)
String minut_change = "0";   // valoare initiala pt minut_change (daca se schimba minut trece in 1)

String sliderValue1_new = "0"; 
String sliderValue2_new = "0"; 
String sliderValue3_new = "0"; 
String sliderValue4_new = "0"; 

String sliderValue1_change = "0";   // valoare initiala pt sliderValue1_change (daca se schimba ora trece in 1)
String sliderValue2_change = "0";   // valoare initiala pt sliderValue2_change (daca se schimba minut trece in 1)
String sliderValue3_change = "0";   // valoare initiala pt sliderValue3_change (daca se schimba minut trece in 1)
String sliderValue4_change = "0";   // valoare initiala pt sliderValue4_change (daca se schimba minut trece in 1)

String ora_val = "20";       // valoare initiala pt ora
String minut_val = "14";     // valoare initiala pt minut


const char* PARAM_INPUT1 = "value1"; //valoare folosita pentru cautarea valorii lui slider1 
                                     // vezi in   xhr.open("GET", "/slider?value1="+sliderValue1, true);
const char* PARAM_INPUT1_CHANGE = "value1_change"; //valoare folosita pentru alerta schimbarii slider1
                                     // vezi in   xhr.open("GET", "/slider?value1_change="+sliderValue1, true);                                     
const char* PARAM_INPUT2 = "value2"; //valoare folosita pentru cautarea valorii lui slider2
                                     // vezi in   xhr.open("GET", "/slider?value2="+sliderValue2, true);
const char* PARAM_INPUT2_CHANGE = "value2_change"; //valoare folosita pentru cautarea valorii lui slider4
                                     // vezi in   xhr.open("GET", "/slider?value2_change="+sliderValue2, true);
const char* PARAM_INPUT3 = "value3"; //valoare folosita pentru cautarea valorii lui slider3
                                     // vezi in   xhr.open("GET", "/slider?value3="+sliderValue3, true);
const char* PARAM_INPUT3_CHANGE = "value3_change"; //valoare folosita pentru cautarea valorii lui slider4
                                     // vezi in   xxhr.open("GET", "/slider?value3_change="+sliderValue3, true); 
const char* PARAM_INPUT4 = "value4"; //valoare folosita pentru cautarea valorii lui slider4
                                     // vezi in   xhr.open("GET", "/slider?value4="+sliderValue4, true);
const char* PARAM_INPUT4_CHANGE = "value4_change"; //valoare folosita pentru cautarea valorii lui slider4
                                     // vezi in   xhr.open("GET", "/slider?value4_change="+sliderValue4, true);                                    

const char* PARAM_INPUT_ORA = "value_ora"; //valoare folosita pentru cautarea valorii ora
                                     // vezi in /xhr.open("GET", "/slider?value_ora="+ora_new, true);
const char* PARAM_INPUT_MINUT = "value_minut"; //valoare folosita pentru cautarea valorii minut
                                     // vezi in  xhr.open("GET", "/slider?value_minut="+minut_new, true);
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
AsyncWebSocket ws("/ws");
byte rosu = 100, verde = 0, albastru = 50, BRIGHTNESS = 5;
byte red, green, blue, umin, zmin, uhour, zhour;
byte dsp_ora [32], dsp_th [32], dsp_tot[96];
byte ma[8], sa[8], za[8], uua[8], utmp[8], ztmp[8], stmp[8], ltmp[8], rtmp[8], mtmp[8];
byte dsp[32], dsp_tmp[32];
byte second, minute, hour, dp;
byte th0, th1, tsgn, kt=0, k;
byte s0, s1, m0, m1, h0, h1;
byte array_disp[256];
float t_read; 
int xxx;
// Set LED GPIO
const int ledPin1 = LED_BUILTIN;

// pin atasat la INT RTC
const byte interruptPin = D5;

// litere si cifre
const byte alfabet [17] [7]=  {{126, 255, 195, 195, 255, 126,   0},      //0
                               {  1, 255, 255,  97,  32,   0,   0},      //1
                               { 99, 243, 219, 207, 199,  99,   0},      //2
                               { 102,255, 219, 219, 195, 102,   0},      //3
                               {  5, 255, 255, 101,  60  ,28,   0},      //4
                               { 78, 223, 211, 211, 251, 250,   0},      //5
                               { 78, 223, 211, 211, 255, 126,   0},      //6
                               {224, 240, 223, 207, 192, 192,   0},      //7
                               {110, 255, 219, 219, 255, 110,   0},      //8
                               {126, 255, 203, 203, 251, 114,   0},      //9
                               {  0,   0,   0,   0,   0,   0,   0},      //blank
                               {102, 102,   0,   0,   0,   0,   0},      //dp
                               {102, 195, 195, 195, 255, 126,   0},      //C
                               {112, 248, 136, 248, 112,   0,   0},      //`
                               {110, 255, 211, 211, 255, 255,   0},      //B
                               { 48,  48,  24,  63,  63,   0,   0},      //r
                               { 24,  24,  24,   0,   0,   0,   0}};     //-


// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val) {
     return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val) {
     return( (val/16*10) + (val%16) );
}
byte x = 0;

byte readEEPROM(int deviceaddress, unsigned int eeaddress ) {
  byte rdata = 0xFF;
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));      //writes the MSB
  Wire.write((int)(eeaddress & 0xFF));    //writes the LSB
  Wire.endTransmission();
  delay(10);
  Wire.requestFrom(deviceaddress,1);
  if (Wire.available()) 
    rdata = Wire.read();
  return rdata;
  }
  
// incepe serverul html
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>CEAS RGB</title>
<style>
html {
    font-family: Arial, Helvetica, sans-serif;
    display: inline-block;
    text-align: center;
  }
  h1 {
    font-size: 1.8rem;
    color: white;
  }
  p {
    font-size: 1.4rem;
  }
  .topnav {
    overflow: hidden;
    background-color: #034078;
  }
  body {
    margin: 0;
  }
  .content {
    padding: 30px;
  }
  .card-grid {
    max-width: 500px;
    margin: 0 auto;
    display: grid;
    grid-gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  }
  .card {
    background-color: white;
    box-shadow: 2px 2px 12px 1px rgba(140,140,140,.5);
  }
  }
  .card-title {
    font-size: 1.2rem;
    font-weight: bold;
    color: #034078
  }
  .state {
    font-size: 1.2rem;
    color:#1282A2;
  }
  .slider {
    -webkit-appearance: none;
    margin: 0 auto;
    width: 90%;
    height: 15px;
    border-radius: 10px;
    background: #C0C0C0;
    outline: none;
  }
  .slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 30px;
    height: 30px;
    border-radius: 50 ;
    background: #034078;
    cursor: pointer;
  }
  .switch {
    padding-left: 5;
  }
    
</style>
</head>
<body>
    <div class="topnav">
        <h1><span style="color:white">CEAS  </span><span style="color:#ff3300">R</span><span style="color:#33cc33">G</span><span style="color:#3399ff">B</span></h1>
    </div>
    <p> </p>
    <span class="inlineinput"><input type="number" onchange="update_ora(this)" id="ora" value="%VAL_ORA%" style='display: inline; width: 120px; font-size:4rem ; text-align: center; 
    color:#ff3300;font-weight: bold; box-shadow: 2px 2px 12px 1px rgba(140,140,140,.5); class="slider"'/></span>
    <span style='display: inline; font-size: 4rem ; text-align: center; color:#ff3300 ; font-weight: bold;'>:</span>
    <span class="inlineinput"> <input type="number" onchange="update_minut(this)" id="minut" value="%VAL_MINUT%"  style='display: inline; width: 120px; font-size:4rem ; text-align: center; 
    color:#ff3300; font-weight: bold;box-shadow: 2px 2px 12px 1px rgba(140,140,140,.5); class="slider"'/></span>
    

    <div class="content">
        <div class="card-grid">
            <div class="card">
                <p class="switch"> <input type="range" onchange="Slider1_change(this)" oninput="updateSlider1(this)" id="Sliderx1" min="0" max="255" value="%SLIDERVALUE1%" step="1" class="slider"></p>
                <p class="state"><span style='color:#ff0000; font-weight: bold;'>ROSU=<span id="textSlider1Value">%SLIDERVALUE1%</span></p>
            </div>
            <div class="card">
                <p class="switch"> <input type="range" onchange="Slider2_change(this)" oninput="updateSlider2(this)" id="Sliderx2" min="0" max="255" value="%SLIDERVALUE2%" step="1" class="slider"></p>
                <p class="state"><span style='color:#33cc33; font-weight: bold;'>VERDE=<span id="textSlider2Value">%SLIDERVALUE2%</span></p>
            </div>
            <div class="card">
                <p class="switch"> <input type="range" onchange="Slider3_change(this)" oninput="updateSlider3(this)" id="Sliderx3" min="0" max="255" value="%SLIDERVALUE3%" step="1" class="slider"></p>
                <p class="state"><span style='color:#0000ff; font-weight: bold;'>ALBASTRU=<span id="textSlider3Value">%SLIDERVALUE3%</span></p>
            </div>
            <div class="card">
                <p class="switch"> <input type="range" onchange="Slider4_change(this)" oninput="updateSlider4(this)" id="Sliderx4" min="1" max="255" value="%SLIDERVALUE4%" step="1" class="slider"></p>
                <p class="state"><span style='color: #797979; font-weight: bold;'>STRALUCIRE=<span id="textSlider4Value">%SLIDERVALUE4%</span></p>
            </div>
        </div>
    </div>
 
<script>


function updateSlider1(element) {
  var sliderValue1 = document.getElementById("Sliderx1").value;
  document.getElementById("textSlider1Value").innerHTML = sliderValue1;
  console.log(sliderValue1);
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "/slider?value1="+sliderValue1, true);
  xhr.send();
}

function Slider1_change(element) {
  var sliderValue1 = document.getElementById("Sliderx1").value;
  document.getElementById("textSlider1Value").innerHTML = sliderValue1;
  console.log(sliderValue1);
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "/slider?value1_change="+sliderValue1, true);
  xhr.send();
}

function updateSlider2(element) {
  var sliderValue2 = document.getElementById("Sliderx2").value;
  document.getElementById("textSlider2Value").innerHTML = sliderValue2;
  console.log(sliderValue2);
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "/slider?value2="+sliderValue2, true);
  xhr.send();
}

function Slider2_change(element) {
  var sliderValue2 = document.getElementById("Sliderx2").value;
  document.getElementById("textSlider2Value").innerHTML = sliderValue2;
  console.log(sliderValue2);
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "/slider?value2_change="+sliderValue2, true);
  xhr.send();
}


function updateSlider3(element) {
  var sliderValue3 = document.getElementById("Sliderx3").value;
  document.getElementById("textSlider3Value").innerHTML = sliderValue3;
  console.log(sliderValue3);
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "/slider?value3="+sliderValue3, true);
  xhr.send();
}

function Slider3_change(element) {
  var sliderValue3 = document.getElementById("Sliderx3").value;
  document.getElementById("textSlider3Value").innerHTML = sliderValue3;
  console.log(sliderValue3);
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "/slider?value3_change="+sliderValue3, true);
  xhr.send();
}

function updateSlider4(element) {
  var sliderValue4 = document.getElementById("Sliderx4").value;
  document.getElementById("textSlider4Value").innerHTML = sliderValue4;
  console.log(sliderValue4);
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "/slider?value4="+sliderValue4, true);
  xhr.send();
}

function Slider4_change(element) {
  var sliderValue4 = document.getElementById("Sliderx4").value;
  document.getElementById("textSlider4Value").innerHTML = sliderValue4;
  console.log(sliderValue4);
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "/slider?value4_change="+sliderValue4, true);
  xhr.send();
}

function update_ora(element) {
  var ora_new = document.getElementById("ora").value;
  console.log(ora_new);
   var xhr = new XMLHttpRequest();
  xhr.open("GET", "/slider?value_ora="+ora_new, true);
  xhr.send();
}

function update_minut(element) {
  var minut_new = document.getElementById("minut").value;
  console.log(minut_new);
   var xhr = new XMLHttpRequest();
  xhr.open("GET", "/slider?value_minut="+minut_new, true);
  xhr.send();
}

</script>
</body>
</html>
)rawliteral";
// sfarsitul serverului html


// Replaces placeholder with button section in your web page
String processor(const String& var){
  //Serial.println(var);
  if (var == "SLIDERVALUE1"){
    return sliderValue1;
  }
  if (var == "SLIDERVALUE2"){
    return sliderValue2;
  }

  if (var == "SLIDERVALUE3"){
    return sliderValue3;
  }

  if (var == "SLIDERVALUE4"){
    return sliderValue4;
  }

  if (var == "VAL_ORA"){
    return ora_val;
  }
  
  if (var == "VAL_MINUT"){
    return minut_val;
  }

  return String();
}

void setup(){
  // Serial port for debugging purposes
  Serial.begin(115200);
  Wire.begin(D2, D1); 
  sensors.begin();
  sensors.setResolution(9);
     // init display
     strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
     strip.show();            // Turn OFF all pixels ASAP
     strip.setBrightness(BRIGHTNESS);
     strip.clear();
     strip.show();
     delay(500); 
     /// Square wave is output on the INT/SQW pin
     Wire.beginTransmission(DS3231_I2C_ADDRESS); // transmit to DS3231 I2C_ADDRESS = 0x68
     Wire.write(byte(0x0E));                     // transmit adress memory  
     Wire.write(0);                              // sends 0 = square output to INT pin
     Wire.endTransmission();                     // stop transmitting
     ////
     pinMode(interruptPin, INPUT);
     pinMode(LED_BUILTIN, OUTPUT);
     //setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year)
     //setDS3231time(0, 9, 00, 7, 18, 04, 22);
     
     sliderValue1 = String(readEEPROM(EEPROM_I2C_ADDRESS, 1));
     sliderValue2 = String(readEEPROM(EEPROM_I2C_ADDRESS, 2));
     sliderValue3 = String(readEEPROM(EEPROM_I2C_ADDRESS, 3));
     sliderValue4 = String(readEEPROM(EEPROM_I2C_ADDRESS, 4));
     
  // Connect to Wi-Fi
  send_web_page();
}

void send_web_page() {
WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }

  // Print ESP Local IP Address
  Serial.println(WiFi.localIP());

  // Route for root / web page
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/html", index_html, processor);
  });

  // Send a GET request to <ESP_IP>/slider?value=<inputMessage>
  server.on("/slider", HTTP_GET, [] (AsyncWebServerRequest *request) {
    String inputMessageslider1;
    String inputMessageslider2;
    String inputMessageslider3;
    String inputMessageslider4;
    String inputMessageora;
    String inputMessageminut;
    
    // GET input1 value on <ESP_IP>/slider1?value1=<inputMessageslider1>
    if (request->hasParam(PARAM_INPUT1)) {
      inputMessageslider1 = request->getParam(PARAM_INPUT1)->value();
      sliderValue1 = inputMessageslider1;
    }
    else {
      inputMessageslider1 = "No message sent";
    }
    if (request->hasParam(PARAM_INPUT1_CHANGE)) {
      sliderValue1_change = "1";
      inputMessageslider1 = request->getParam(PARAM_INPUT1_CHANGE)->value();
      sliderValue1_new = inputMessageslider1;
    }
    else {
      inputMessageslider1 = "No message sent";
    }
    
    // GET input1 value on <ESP_IP>/slider2?value2=<inputMessageslider2>
    if (request->hasParam(PARAM_INPUT2)) {
      inputMessageslider2 = request->getParam(PARAM_INPUT2)->value();
      sliderValue2 = inputMessageslider2;
    }
    else {
      inputMessageslider2 = "No message sent";
    }
    if (request->hasParam(PARAM_INPUT2_CHANGE)) {
      sliderValue2_change = "1";
      inputMessageslider2 = request->getParam(PARAM_INPUT2_CHANGE)->value();
      sliderValue2_new = inputMessageslider2;
    }
    else {
      inputMessageslider2 = "No message sent";
    }
    
 
    // GET input1 value on <ESP_IP>/slider3?value3=<inputMessageslider3>
    if (request->hasParam(PARAM_INPUT3)) {
      inputMessageslider3 = request->getParam(PARAM_INPUT3)->value();
      sliderValue3 = inputMessageslider3;
    }
    else {
      inputMessageslider3 = "No message sent";
    }  
    if (request->hasParam(PARAM_INPUT3_CHANGE)) {
      sliderValue3_change = "1";
      inputMessageslider3 = request->getParam(PARAM_INPUT3_CHANGE)->value();
      sliderValue3_new = inputMessageslider3;
    }
    else {
      inputMessageslider3 = "No message sent";
    } 

    if (request->hasParam(PARAM_INPUT4)) {
      inputMessageslider4 = request->getParam(PARAM_INPUT4)->value();
      sliderValue4 = inputMessageslider4;
     }
    else {
      inputMessageslider4 = "No message sent";
    }

    if (request->hasParam(PARAM_INPUT4_CHANGE)) {
      sliderValue4_change = "1";
      inputMessageslider4 = request->getParam(PARAM_INPUT4_CHANGE)->value();
      sliderValue4_new = inputMessageslider4;
    }
    else {
      inputMessageslider4 = "No message sent";
    }


    // GET input1 value on <ESP_IP>/slider4?value4=<inputMessageslider4>  

    if (request->hasParam(PARAM_INPUT_ORA)) {
      ora_change = "1";
      inputMessageora = request->getParam(PARAM_INPUT_ORA)->value();
      ora_new =  inputMessageora;
    }
    else {
      inputMessageora = "No message sent";
    }

    if (request->hasParam(PARAM_INPUT_MINUT)) {
      minut_change = "1";
      inputMessageminut = request->getParam(PARAM_INPUT_MINUT)->value();
      minut_new = inputMessageminut;
    }
    else {
      inputMessageminut = "No message sent";
    }


    
    request->send(200, "text/plain", "OK");
  });
  
  // Start server
  server.begin();
  
}

void I2Cwrite(byte ID, byte adress, byte value) {
      Wire.beginTransmission(ID); //select ID device
      Wire.write(adress); // move pointer to adress address 
      Wire.write(value); // sends value
      Wire.endTransmission();
     }

void I2CRead(uint8_t ID, uint8_t adress, byte *xxx) {
     Wire.beginTransmission(ID);
     Wire.write(adress); // set DS3231 register pointer to 00h
     Wire.endTransmission();
     Wire.requestFrom((uint8_t) ID, (uint8_t) 1);
     // request seven bytes of data from DS3231 starting from register 00h
     *xxx = Wire.read();
}

void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year) {
     // sets time and date data to DS3231
     Wire.beginTransmission(DS3231_I2C_ADDRESS);
     Wire.write(0); // set next input to start at the seconds register
     Wire.write(decToBcd(second)); // set seconds
     Wire.write(decToBcd(minute)); // set minutes
     Wire.write(decToBcd(hour)); // set hours
     Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
     Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
     Wire.write(decToBcd(month)); // set month
     Wire.write(decToBcd(year)); // set year (0 to 99)
     Wire.endTransmission();
}
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data ) {
     Wire.beginTransmission(deviceaddress);
     Wire.write((int)(eeaddress >> 8));      //writes the MSB
     Wire.write((int)(eeaddress & 0xFF));    //writes the LSB
     Wire.write(data);
     delay(10);
     Wire.endTransmission();
     delay(10);
}
  
void read_RTC() {
     Wire.beginTransmission(DS3231_I2C_ADDRESS);
     Wire.write(0); // set DS3231 register pointer to 00h
     Wire.endTransmission();
     Wire.requestFrom(DS3231_I2C_ADDRESS, 3);
     // request seven bytes of data from DS3231 starting from register 00h
     second = bcdToDec(Wire.read() & 0x7f);
     s0 = second /10;
     s1 = second %10;
     minute = bcdToDec(Wire.read());
     m0 = minute/10;
     m1 = minute %10;
     hour = bcdToDec(Wire.read() & 0x3f);
     h0 = hour/10;
     h1 = hour %10;
    
    if (hour <= 9) {
        ora_val = "0" + String(hour);
    }    
    else {
       ora_val = String(hour);
    }

    if (minute <= 9) {
        minut_val = "0" + String(minute);
    }    
    else {
        minut_val = String(minute);
    }
}

void read_temperature() {
     t_read = sensors.getTempCByIndex(0);
     //Serial.println(t_read);
     xxx = t_read;
     if (xxx < 0) {
        tsgn = 16;
        xxx = -xxx;
     }
     else {
        tsgn = 10;
     }
     th0 = xxx / 10;     
     th1 = xxx % 10;
}

//Prepare hour data
 void prepare_to_show_hour(byte m, byte s_, byte z_, byte u_i, byte dp1){
     
     for(int i = 0; i <= 31; i++) {
         dsp_ora [i] = 0;
     }
        
     for(int i=0; i<=2; i++) { 
        if (dp ==1) {
           dsp_ora [i+14] = alfabet [11] [i];
        }
        else {
           dsp_ora [i+14] = alfabet [10] [i];
        }
     }
      
      for(int i = 0; i <= 5; i++) { 
        dsp_ora [i] = alfabet [u_i] [i];
        dsp_ora [i+7] = alfabet [z_] [i];
        dsp_ora [i+17] = alfabet [s_] [i];
        dsp_ora [i+24] = alfabet [m] [i];
      }
      for(int i = 0; i <= 31; i++) {
        dsp_tot[i] = dsp_ora [i] ;
        dsp_tot[i+64] = dsp_ora [i] ;
        }

     for(int i=0; i<=255; i++) { // For each pixel in strip...
         k = i % 16;
         byte j = i/8;
         byte k1 = 8*(j+1)-(i % 8) - 1;
         int bt = bitRead(dsp_ora [j], i%8);
         array_disp[i] = bt;
     }
 }
 
// Prepare Temperature data
void prepare_to_show_temp(byte tsgn, byte iz_, byte iu){
     for(int i = 0; i <= 31; i++) {
         dsp_th [i] = 0;
     }
     for(int i = 0; i <= 5; i++) { 
        dsp_th [i+1] = alfabet [12] [i];
        dsp_th [i+8] = alfabet [13] [i];
        dsp_th [i+14] = alfabet [iu] [i];
        dsp_th [i+21] = alfabet [iz_] [i];
        dsp_th [i+28] = alfabet [tsgn] [i];
     }

     for(int i = 0; i <= 31; i++) {
        dsp_tot[i+32] = dsp_th [i] ;
     }
     for(int i=0; i<=255; i++) { // For each pixel in strip...
         k = i % 16;
         byte j = i/8;
         byte k1 = 8*(j+1)-(i % 8) - 1;
         int bt = bitRead(dsp_th [j], i%8);
         array_disp[i] = bt;
     }    
}

void tranz_display(byte kk) {
     for(byte i = 0; i <= 31; i++) {
         dsp_tmp[i] = dsp_tot[i+64 - kk];
     }
   
     for(int i=0; i<=255; i++) { // For each pixel in strip...
         k = i % 16;
         byte j = i/8;
         byte k1 = 8*(j+1)-(i % 8) - 1;
         int bt = bitRead(dsp_tmp[j], i%8);
         array_disp[i] = bt;
     }   
}

void read_sliders() {
     rosu = sliderValue1.toInt();
     verde = sliderValue2.toInt();
     albastru = sliderValue3.toInt(); 
     BRIGHTNESS= sliderValue4.toInt();
}

void change_controls(){
    if (ora_change.toInt() == 1) {
       ora_change = "0";
       I2Cwrite(DS3231_I2C_ADDRESS, 2, decToBcd(ora_new.toInt()));
    }

    if (minut_change.toInt() == 1) {
       minut_change = "0";
       I2Cwrite(DS3231_I2C_ADDRESS, 1, decToBcd(minut_new.toInt()));
       I2Cwrite(DS3231_I2C_ADDRESS, 0, 0);
    }
    
    if (sliderValue1_change.toInt() == 1) {
       sliderValue1_change  = "0";
       writeEEPROM(EEPROM_I2C_ADDRESS, 1, sliderValue1_new.toInt()); 
    }
    if (sliderValue2_change.toInt() == 1) {
       sliderValue2_change  = "0";
       writeEEPROM(EEPROM_I2C_ADDRESS, 2, sliderValue2_new.toInt()); 
    }
    if (sliderValue3_change.toInt() == 1) {
       sliderValue3_change  = "0";
       writeEEPROM(EEPROM_I2C_ADDRESS, 3, sliderValue3_new.toInt()); 
    }
 
    if (sliderValue4_change.toInt() == 1) {
       sliderValue4_change  = "0";
       writeEEPROM(EEPROM_I2C_ADDRESS, 4, sliderValue4_new.toInt()); 
    }  
}

void show_data(){ 
     read_sliders();
     strip.setBrightness(BRIGHTNESS);  
     dp = digitalRead(interruptPin);
     digitalWrite(LED_BUILTIN, !dp);   
     for(int i=0; i<=255; i++) { // For each pixel in strip...
         byte k = i % 16;
         byte j = i/8;
         byte k1 = 8*(j+1)-(i % 8) - 1;
         byte bt = array_disp[i]; 
         red = rosu * bt ;
         green =  verde * bt ;
         blue =  albastru * bt ; 
         if (k <=7) {
            strip.setPixelColor(i, red,green,blue);         //  Set pixel's color (in RAM)
         }
         else {
            strip.setPixelColor(k1, red,green,blue);         //  Set pixel's color (in RAM)
         }
     }
     strip.show();
}
void show_hour(){
     prepare_to_show_hour(h0, h1, m0, m1, dp);
     prepare_to_show_temp(tsgn, th0, th1);
     tranz_display(0);
     show_data(); 
}
void show_hour_to_temp(){
     dp = 1;
     for(int yy = 0; yy <= 32; yy++) { 
         tranz_display(yy);
         show_data();
         delay(40);                
     }
}

void show_temp(){
     tranz_display(32);
     show_data();
     for(int yy = 0; yy <= 300; yy++) {
        show_data();
        delay(1); 
     }
}

void show_temp_to_hour(){
     for(int yy = 0; yy <= 32; yy++) { 
        tranz_display(yy+32);
        show_data();
        delay(40);                
     }
}

  
void loop() {
  if (dp != digitalRead(interruptPin)) {
      Serial.println( ESP.getFreeHeap());
      kt = kt + 1;
      if (kt == 28) {
         kt = 0;
      }      
      dp = digitalRead(interruptPin);
      digitalWrite(LED_BUILTIN, !dp);
      
      if ((kt % 4) == 0 ) {
         read_temperature();
      }
      else {
        if ((kt % 4) == 2) {
            sensors.requestTemperatures();
        } 
      }
  }
     
    change_controls();
    read_RTC(); 
    show_hour(); 

    if  (dp == 1) {
        if ((second == 5) || (second == 25) || (second == 45)) {
           show_hour_to_temp();
           show_temp();
           show_temp_to_hour();   
        }
    }
      ws.cleanupClients();          
}

 

Have a fun!

Editat de Kreator
Link spre comentariu
  • Răspunsuri 46
  • Creat
  • Ultimul Răspuns

Top autori în acest subiect

Top autori în acest subiect

Imagini postate

Frumos proiect.
Si mai frumos era daca nu continea "delay".
Nu stiu altii cum sunt, dar eu cand vad utilizata delay() am ceva de comentat.
Si , evident, se putea optimiza putin codul. Cred ca merge scris cu mai putin de 50% dintre liniile de cod de acum.

 

Editat de Vizitator
Link spre comentariu

Delay() , ca metoda, trebuie evitata.
Timpi de intarziere sunt, normal, necesari uneori pentru anumite activitati.
Dar, ideal, se pot obtine cu timere.
Si Dumnezeu a facut o pauza dupa facerea lumii. Dar singur nu a stat degeaba in acest timp. S-a gandit EL la ceva ...
Ideea mea este ca in activitatea umana nu exista echivalent pentru "delay()". Nici macar somul nu este un delay profund.
De ce sa-l folosim in programare ?
 

Editat de Vizitator
Link spre comentariu
36 minutes ago, Liviu.Mihaiu said:

Delay() , ca metoda, trebuie evitata.

Tu ai citit ce scrie in link-ul pus de @Liviu M?

 

Quote

Remember that there is a lot of code that needs to run on the chip besides the sketch when WiFi is connected. WiFi and TCP/IP libraries get a chance to handle any pending events each time the loop() function completes, OR when delay is called. If you have a loop somewhere in your sketch that takes a lot of time (>50ms) without calling delay, you might consider adding a call to delay function to keep the WiFi stack running smoothly.

There is also a yield() function which is equivalent to delay(0). The delayMicroseconds function, on the other hand, does not yield to other tasks, so using it for delays more than 20 milliseconds is not recommended.

 

 

P.S. @Liviu M am o curiozitate: esti si tu pescar?

Editat de merck
Link spre comentariu

Canci. O părare a unui Gigel (ca si mine) despre programare (ma refer la zicerile din link).
Dacă-l aude un Linus Benedict Torvalds sau (chiar si un) Gates Bill se cacă pe el de râs.
Daca delay() se utiliza prin sistemele de operare, telefoane sau routere ... aveam acces la net dupa o saptamana de la pornirea dispozitivului :)
Hai sa fim seriosi si sa nu mai credem toate c
ăcaturile scrise pe post de "cele 10 porunci" pe net.




 

Editat de Vizitator
Link spre comentariu
3 minutes ago, yo8tot said:

Mai ales cand nu ai nici un OS.

Vorbesti de RTOS mai curand.

 

Altfel, am mai zis si eu alta data: pune dta @Liviu.Mihaiucodul optimizat si o sa iti multumim cu totii pentru efort, altfel, ramanem cu buza umflata iar (ca ultima oara, tot la dodo te-ai dus cand ti s-a sugerat sa pui codul).

Link spre comentariu
1 hour ago, Liviu.Mihaiu said:

Canci. O părare a unui Gigel

Gigel ala s-a ocupat de integrat esp8266 in mediul Arduino. Parca l-as crede mai tare pe el decat pe tine. 

PS Nici linux, nici dos nu-s sisteme de operare in timp real, probabil n-au nevoie de delay() ca sa "piarda" timp.

 

1 hour ago, merck said:

P.S. @Liviu M am o curiozitate: esti si tu pescar?

Nu, de ce?

Ma rog, am prins pe vremuri niste guvizi si cativa sparilloni, da' de aici pana la pescar...

Link spre comentariu
Acum 18 ore, Liviu.Mihaiu a spus:

Canci. O părare a unui Gigel (ca si mine) despre programare (ma refer la zicerile din link).
Dacă-l aude un Linus Benedict Torvalds sau (chiar si un) Gates Bill se cacă pe el de râs.
Daca delay() se utiliza prin sistemele de operare, telefoane sau routere ... aveam acces la net dupa o saptamana de la pornirea dispozitivului :)
Hai sa fim seriosi si sa nu mai credem toate c
ăcaturile scrise pe post de "cele 10 porunci" pe net.

 

Controleaza-ti vocabularul! Si inca ceva: aici nu vorbim despre sisteme de operare ci despre o aplicatie practica, folosind mediul Arduino care, intamplator sau nu, foloseste si delay() indiferent daca tie iti place sau nu, sau daca tu folosesti sau nu afeasta functie. Delay foloseste oricum un timer aşa că....

Link spre comentariu

@nico_2010
Aplicatie practica (cu vocabular controlat) :
Softul de mai sus se poate adapta pentru a controla o drona folosind pagina web.
Vom adauga un senzor de proximitate pentru a evita ca drona sa se loveasca de obstacole.

Daca de fiecare data cand se pierde conexiunea wireless softul din drona tot face "delay", este foarte probabil sa o gasim lipita de un perete.

 

Link spre comentariu

Creează un cont sau autentifică-te pentru a adăuga comentariu

Trebuie să fi un membru pentru a putea lăsa un comentariu.

Creează un cont

Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!

Înregistrează un nou cont

Autentificare

Ai deja un cont? Autentifică-te aici.

Autentifică-te acum



×
×
  • Creează nouă...

Informații Importante

Am plasat cookie-uri pe dispozitivul tău pentru a îmbunătății navigarea pe acest site. Poți modifica setările cookie, altfel considerăm că ești de acord să continui.Termeni de Utilizare si Ghidări