Boisse Martin
Published

Making a Cheap Aquarium Parameters Controller

You will be able to create a small aquarium assistant which will switch on/off the light and control water parameters automatically.

IntermediateFull instructions provided5 hours17,374
Making a Cheap Aquarium Parameters Controller

Things used in this project

Hardware components

ESP8266 ESP-12E
Espressif ESP8266 ESP-12E
×2
Arduino UNO
Arduino UNO
×1
SparkFun Logic Level Converter - Bi-Directional
SparkFun Logic Level Converter - Bi-Directional
×1
NeoPixel strip
NeoPixel strip
×1
MCP3008
×1
Resistor 10k ohm
Resistor 10k ohm
depends on the sensor you'll use.
×2
Temperature Sensor
Temperature Sensor
×1
Photo resistor
Photo resistor
×1

Software apps and online services

Arduino IDE
Arduino IDE
Maker service
IFTTT Maker service

Story

Read more

Code

ESP8266 - Sensor Side

C/C++
Put it into your ESP8266 (the one which is connected to the sensors).
Makes sure that you've changed the SSID/Password and the board terminals.
/*********
  Projet objet connect
  Aminata Diagne - Martin Boisse

  Groupe Sensaqua

  Code prsent sur l'ESP ct capteurs
*********/

#include <Wire.h>
#include <ESP8266WiFi.h>
#include <Arduino.h>
#include <MCP3008.h>
// Heure
#include <TimeLib.h>
#include <NtpClientLib.h>

//define pin connections
#define CS_PIN D8
#define CLOCK_PIN D5
#define MOSI_PIN D7
#define MISO_PIN D6

// Valeurs borne des paramtres
#define MIN_TEMP 23
#define MAX_TEMP 27

#define MIN_PH 6.3
#define MAX_PH 7.5

#define MIN_SALINITE 1.022
#define MAX_SALINITE 1.025

#define MIN_NITRATE 0
#define MAX_NITRATE 50

// Variable de temps
int time_add;
bool flag; 

MCP3008 adc(CLOCK_PIN, MOSI_PIN, MISO_PIN, CS_PIN);

//Sensor values
float val_temp;
float val_lum;
float val_nitrate;
float val_salinite;
float val_ph;

const char* ssid = "Livebox-S3X3";
const char* password = "grossebite";

// const char* ssid = "AndroidAP";
// const char* password = "zypy3306";

// Pour l'envoie de message
const char* host = "maker.ifttt.com";
const int httpsPort = 443;

// Web Server on port 80
WiFiServer server(80);

/* ------------------------------ SETUP ------------------------------ */
void setup() {
  // Initializing serial port for debugging purposes
  Serial.begin(115200);
  delay(10);
  Wire.begin(D3, D4);
  Wire.setClock(100000);
  // Connecting to WiFi network
  Serial.println();
  Serial.print("En train de se connecter  ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("ESP est connect");
  
  // Starting the web server
  server.begin();
  Serial.println("Le server web fonctionne. En attente de l'adresse IP de l'ESP...");
  delay(10000);
  
  // Affichage de l'adresse IP
  Serial.println(WiFi.localIP());

  //Mise  0 du temps
  time_add = 0;
  flag = true;

  // Get l'heure pour grer la luminosit
  NTP.begin("pool.ntp.org", 1, true);
  NTP.setInterval(1000);

  Serial.print("Got NTP time: ");
  Serial.println(NTP.getTimeDateString(NTP.getLastNTPSync()));

}

/* ----------------------------------------------------------------------- */

/* ----------------------------- ALLUMAGE LED ---------------------------- */

/*
  Obtention de l'heure et envoie de la commande d'allumage des LED
*/

void setLED() {

  int value;

  // Get de l'heure
  String heure = NTP.getTimeDateString(NTP.getLastNTPSync());

  // Jour / Nuit
  bool jour = true;
  if(heure[0] == '8')
    jour = true;
  else if(heure[0] == '2' && heure[1] == '0')
    jour = false;

  if(jour)
    OnLed();
  else if(!jour)
    OffLed(); 

  // Ajustement en fonction de la luminosit
  if (luminosite < 850 )
    value = HIGH;
  else if (luminosite >= 850 )
    value = LOW;

}

void OnLed()  {

  // Connection vers ESP_LED (TCP)

  const char* host_ESP_LED = "192.168.43.237";
  WiFiClient client_ESP;
  const int httpPort = 80;

  if (!client_ESP.connect(host_ESP_LED, httpPort)) {
    Serial.println("connection failed");
    return;
  }

  Serial.print("connecting to ");
  Serial.println(host_ESP_LED);

  String url = "/ON";

  // This will send the request to the server
  client_ESP.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host_ESP_LED + "\r\n" + 
               "Connection: close\r\n\r\n");
  unsigned long timeout = millis();
  while (client_ESP.available() == 0) {
    if (millis() - timeout > 5000) {
      Serial.println(">>> Client Timeout !");
      client_ESP.stop();
      return;
    }
  }
}

void OffLed() {

  // Connection vers ESP_LED (TCP)

  const char* host_ESP_LED = "192.168.43.237";
  WiFiClient client_ESP;
  const int httpPort = 80;

  if (!client_ESP.connect(host_ESP_LED, httpPort)) {
    Serial.println("connection failed");
    return;
  }

  Serial.print("connecting to ");
  Serial.println(host_ESP_LED);

  String url = "/OFF";

  // This will send the request to the server
  client_ESP.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host_ESP_LED + "\r\n" + 
               "Connection: close\r\n\r\n");
  unsigned long timeout = millis();
  while (client_ESP.available() == 0) {
    if (millis() - timeout > 5000) {
      Serial.println(">>> Client Timeout !");
      client_ESP.stop();
      return;
    }
  }
}

/* ----------------------------------------------------------------------- */

/* ------------------------------ GET PARAM ------------------------------ */

/*
  Obtention des paramtres grce au MCP3008
*/

void getParam() {

  val_lum = adc.readADC(0); // Li le channel 0 du MCP3008 (pin 1)
  val_temp = adc.readADC(2) * (3.3*10/1023);
  val_ph = adc.readADC(5);
  val_salinite = adc.readADC(3);
  val_nitrate = adc.readADC(4);  

  delay(5000);
}

/* ----------------------------------------------------------------------- */

/* ----------------------------- SEND MESSAGE ---------------------------- */

/*
  Envoie du message d'alerte
*/

void sendMessage()  {

  if(flag == true)  {
    Serial.print("-------------- Envoie du message d'alerte --------------");
    WiFiClientSecure client;
    Serial.print("Connection  ");
    Serial.println(host);
    if (!client.connect(host, httpsPort)) {
      Serial.println("Connection echoue");
      return;
    }

    // Trouv sur le site IFTTT
    String url = "write your own";

    Serial.print("Appel de l'url suivant: ");
    Serial.println(url);
    // Envoie de la requte
    client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                "Host: " + host + "\r\n" +
                "User-Agent: BuildFailureDetectorESP8266\r\n" +
                "Connection: close\r\n\r\n");
    Serial.println("Requte envoye");
    while (client.connected()) {
      String line = client.readStringUntil('\n');
      if (line == "\r") {
        Serial.println("requte reue");
        break;
      }
    } 
    String line = client.readStringUntil('\n');
    Serial.println("La rponse a t:");
    Serial.println("==========");
    Serial.println(line);
    Serial.println("==========");
    Serial.println("Fermeture de la connection");
  
    // Mise en attente du prochain SMS
    flag = false;
  }

}

/* ----------------------------------------------------------------------- */

/* --------------------------------- LOOP -------------------------------- */

void loop() {

  setLED();

  /* ----------------- Contrle des paramtres ----------------- */

  getParam();

  if(val_temp > MAX_TEMP || val_temp < MIN_TEMP)  
    sendMessage();
  // if(val_ph > MAX_PH || val_ph < MIN_PH)
  //   sendMessage();
  // if(val_salinite > MAX_SALINITE ||val_salinite < MIN_SALINITE)
  //   sendMessage();
  // if(val_nitrate > MAX_NITRATE || val_nitrate < MIN_NITRATE)
  //   sendMessage();  

  /* ------------------------------------------------------------ */

  /* ----------------- Limiter le nombre de SMS ----------------- */

  time_add++;
  if(time_add > 8000) {
    flag = true;
    time_add = 0;
  }

  /* ------------------------------------------------------------ */

  /* ------------ Ct Serveur WEB - coute client -------------- */

  // En ecoute pour de nouveaux clients
  WiFiClient client = server.available();
  
  if (client) {
    Serial.println("New client");
    // bolean to locate when the http request ends
    boolean blank_line = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        
        if (c == '\n' && blank_line) {

            /* ----------------- Affichage de la page Web ----------------- */

            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: text/html");
            client.println("Connection: close");
            client.println();
            // Web Page intro
            client.println("<!DOCTYPE HTML>");
            client.println("<html>");
            client.println("<head><META HTTP-EQUIV=\"refresh\" CONTENT=\"15\">");
            client.println("<style>");
            client.println("body  {");
            client.println("background: url(\"/img/background.png\");");
            client.println("background-repeat: no-repeat;");
            client.println("background-size: 53%;}");
            client.println("h4    {");
            client.println("font-family: verdana;");
            client.println("color: #FF4000;}");
            client.println("h3    {");
            client.println("font-family: verdana;");
            client.println("font-weight: bold;");
            client.println("color: teal;}");
            client.println("</style>");
            client.println("</head>");
            // Body
            client.println("<body>");
            client.println("<table border=\"2\" width=\"405\" cellpadding=\"10\">");
            client.println("<tbody>");
            client.println("<tr>");
            client.println("<td>");
            client.println("<h4>Temperature min: ");
            client.println(MIN_TEMP);
            client.println("&deg;C</h4>");
            client.println("<h3>Temperature actuelle: ");
            //Affichage temperature
            client.println(val_temp);
            Serial.print(val_temp);
            client.println("&deg;C</h3>");
            client.println("<h4>Temperature max: ");
            client.println(MAX_TEMP);
            client.println("&deg;C</h4></td></tr>");
            client.println("<tr><td>");
            client.println("<h4>Ph min: ");
            client.println(MIN_PH);
            client.println("</h4>");
            client.println("<h3>Ph actuel: ");
            //Affichage PH
            client.println(val_ph);
            client.println("</h3>");
            client.println("<h4>Ph max: ");
            client.println(MAX_PH);
            client.println("</h4></td></tr>");
            client.println("<tr><td>");
            client.println("<h4>Salinit&eacute; min: ");
            client.println(MIN_SALINITE);
            client.println("</h4>");
            client.println("<h3>Salinit&eacute; actuelle: ");
            //Affichage salinite
            client.println(val_salinite);
            client.println("</h3>");
            client.println("<h4>Salinit&eacute; max: ");
            client.println(MAX_SALINITE);
            client.println("</h4></td></tr>");
            client.println("<tr><td>");
            client.println("<h4>Taux de nitrate min: ");
            client.println(MIN_NITRATE);
            client.println("mg/Litre</h4>");
            client.println("<h3>Taux de nitrate actuel: ");
            //Affichage nitrate
            client.println(val_nitrate);
            client.println("</h3>");
            client.println("<h4>Taux de nitrate max: ");
            client.println(MAX_NITRATE);
            client.println("mg/Litre</h4></td></tr>");
            // Fin Page
            client.println("</tbody></table></body></html>");

            /* ------------------------------------------------------------ */

            break;
        }
        if (c == '\n') {
          // when starts reading a new line
          blank_line = true;
        }
        else if (c != '\r') {
          // when finds a character on the current line
          blank_line = false;
        }
      }
    }  
    // closing the client connection
    delay(1);
    client.stop();
    Serial.println("Client disconnected.");
  }

  /* ------------------------------------------------------------ */

} 

/* ----------------------------------------------------------------------- */

Wifi_led.ino

C/C++
This is for ESP8266 that receive the command to switch on/off the light.
#include  <ESP8266WiFi.h>
#include  <ESP8266WiFiMulti.h>  
#include  <ESP8266mDNS.h>
#include  <ESP8266WebServer.h>


ESP8266WiFiMulti  wifiMulti;          //  Create  an  instance  of  the ESP8266WiFiMulti  class,  called  'wifiMulti'
ESP8266WebServer  server(80);       //  Create  a webserver object  that  listens for HTTP  request on  port  80

/********Prototypes***************/
void handleNotFound();
void allumage(void);
void extinction(void);
void modularite(void);

/**********************************/

String addr_client = "192.168.43.10"; // pour repondre a la requete d'un seul IP.
String addr_test ; 
String type,dat ; 


/*********************************/


void  setup(void){
    Serial.begin(115200);                 //  Start the Serial  communication to  send  messages  to  the computer
    wifiMulti.addAP("AndroidAP", "zypy3306");      //  add Wi-Fi networks  you want  to  connect to
    //Serial.println("Connecting  ...");
    int i = 0;
    while (wifiMulti.run()  !=  WL_CONNECTED) { //  Wait  for the Wi-Fi to  connect:  scan  for Wi-Fi networks, and connect to  the strongest of  the networks  above
        delay(250);
       // Serial.print('.');
    }
   // Serial.println('\n');
    //Serial.print("Connected to  ");
   // Serial.println(WiFi.SSID());                            //  Tell  us  what  network we're connected to
    //Serial.print("IP  address:\t");
    //Serial.println(WiFi.localIP());                     //  Send  the IP  address of  the ESP8266 to  the computer
    if  (MDNS.begin("esp8266")) {                           //  Start the mDNS  responder for esp8266.local
      //  Serial.println("mDNS  responder started");
    } else  {
        //Serial.println("Error setting up  MDNS  responder!");
    }

  
    server.on("/ON",  HTTP_GET, allumage); 
    server.on("/OFF",  HTTP_GET, extinction); 
    server.on("/MOD",  HTTP_GET,modularite); 
    server.onNotFound(handleNotFound);                //  When  a client  requests  an  unknown URI (i.e. something other than  "/"), call  function "handleNotFound"
    server.begin();                                                     //  Actually  start the server
    
   // Serial.println("HTTP  server  started");
}

/*****************************************/
void  loop(void){
    server.handleClient();                                        //  Listen  for HTTP  requests  from  clients
}
/*****************************************/

void  handleNotFound(){
    server.send(404,  "text/plain", "404: Not found");  //  Send  HTTP  status  404 (Not  Found)  when  there's no  handler for the URI in  the request
}
/*****************************************/
void allumage(void){
addr_test = server.client().remoteIP().toString(); 
  if(addr_test == addr_client){
    Serial.print('A');
    server.send(200);
  }
}
/*****************************************/
void extinction(void){

 addr_test = server.client().remoteIP().toString(); 
 if(addr_test == addr_client){
    Serial.print('E'); 
    server.send(200);
  }
}
/*****************************************/
void modularite(void){
  
  
  addr_test = server.client().remoteIP().toString();   
  if(addr_test == addr_client){
    type = server.arg(0);
        
    dat = 'M';
    dat +=';'; 
    dat +=type; 
  
    Serial.print(dat);
    server.send(200);
 }
  
}

matrix_led.ino

C/C++
This is for the Arduino Uno. It switch on/off the light when esp tells it.
/********************************************************************* 
 Adafruit invests time and resources providing this open source code,
 please support Adafruit and open-source hardware by purchasing
 products from Adafruit!

 MIT license, check LICENSE for more information
 All text above, and the splash screen below must be included in
 any redistribution
*********************************************************************/
#include <Adafruit_NeoPixel.h>
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>

/*=========================================================================
    APPLICATION SETTINGS
                              
    MATRIX DECLARATION        Parameter 1 = width of NeoPixel matrix
                              Parameter 2 = height of matrix
                              Parameter 3 = pin number (most are valid)
                              Parameter 4 = matrix layout flags, add together as needed:
    NEO_MATRIX_TOP,
    NEO_MATRIX_BOTTOM,
    NEO_MATRIX_LEFT,
    NEO_MATRIX_RIGHT          Position of the FIRST LED in the matrix; pick two, e.g.
                              NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
                              NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal
                              rows or in vertical columns, respectively; pick one or the other.
    NEO_MATRIX_PROGRESSIVE,
    NEO_MATRIX_ZIGZAG         all rows/columns proceed in the same order, 
                              or alternate lines reverse direction; pick one.

                              See example below for these values in action.
    
    Parameter 5 = pixel type flags, add together as needed:
                              
    NEO_KHZ800                800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
    NEO_KHZ400                400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
    NEO_GRB                   Pixels are wired for GRB bitstream (most NeoPixel products)
    NEO_RGB                   Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
    -----------------------------------------------------------------------*/
    #define FACTORYRESET_ENABLE     1

    #define PIN                     6   // Which pin on the Arduino is connected to the NeoPixels
    #define width                   2
    #define height                  15

// Example for NeoPixel 8x8 Matrix.  In this application we'd like to use it 
// with the back text positioned along the bottom edge.
// When held that way, the first pixel is at the top left, and
// lines are arranged in columns, zigzag order.  The 8x8 matrix uses
// 800 KHz (v2) pixels that expect GRB color data.
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(width, height, PIN,
  NEO_MATRIX_TOP     + NEO_MATRIX_LEFT+
  NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE,
  NEO_GRB            + NEO_KHZ800);
/*=========================================================================*/
#include <SoftwareSerial.h>

SoftwareSerial mySerial(0, 1); // RX, TX

String data ; 
int type ; 

/*=========================================================================*/

void setup(void)
{
  pinMode(PIN, OUTPUT);      // sets the digital pin 6 as output
  matrix.begin();
  matrix.setBrightness(50);
  matrix.fillScreen(0);
  matrix.show(); // This sends the updated pixel colors to the hardware.

  Serial.begin(115200);
  Serial.println("Arduino ready");
  mySerial.begin(115200);
  
}

/*=========================================================================*/

void loop(void)
{
   if (mySerial.available() > 0){ 
     data = mySerial.readString(); // Lecture des donnes arrivant sur le port serie
     
      if(data[0] == 'A'){
        Serial.println("allumage");
        allumage_progressif();
      }

     else if(data[0] == 'E'){
        Serial.println("extinction");
        extinction_progressif();
      }

      else if(data[0] == 'M'){
         Serial.println("\nmodulation");
         
         // Parse of String data
         type = data[2] -'0';
                    
         Serial.print("type = ");
         Serial.print(type);
         modulation_luminosite(type);
        }
   }
  
}

/*=========================================================================*/
/*=========================================================================*/
void allumage_progressif(void){
  /******Lumire rouge *******/
  matrix.drawPixel(0, 2, matrix.Color(255,0,0)); // x, y, color
  matrix.drawPixel(0,12, matrix.Color(255,0,0)); // x, y, color
  
  matrix.drawPixel(1, 7, matrix.Color(255,0,0)); // x, y, color
  matrix.show(); // This sends the updated pixel colors to the hardware.

  // Attente de 3 min 
  //delay(18000);
  delay(2000); // 2 s

   /******Lumire Bleue *******/
  matrix.drawPixel(0, 1, matrix.Color(0,0,255)); // x, y, color
  matrix.drawPixel(0, 3, matrix.Color(0,0,255)); // x, y, color
  matrix.drawPixel(0, 7, matrix.Color(0,0,255)); // x, y, color
  matrix.drawPixel(0, 11, matrix.Color(0,0,255)); // x, y, color
  matrix.drawPixel(0, 13, matrix.Color(0,0,255)); // x, y, color

  matrix.drawPixel(1, 12, matrix.Color(0,0,255)); // x, y, color
  matrix.drawPixel(1, 8, matrix.Color(0,0,255)); // x, y, color
  matrix.drawPixel(1, 6, matrix.Color(0,0,255)); // x, y, color
  matrix.drawPixel(1, 2, matrix.Color(0,0,255)); // x, y, color
  matrix.show(); // This sends the updated pixel colors to the hardware.
  
  // Attente de 10 min 
  //delay(60000);
  delay(4000); // 4 s

   /******Lumire Blanche *******/
  matrix.drawPixel(0, 0, matrix.Color(255,255,255)); // x, y, color
  matrix.drawPixel(0, 4, matrix.Color(255,255,255)); // x, y, color
  matrix.drawPixel(0, 5, matrix.Color(255,255,255)); // x, y, color
  matrix.drawPixel(0, 6, matrix.Color(255,255,255)); // x, y, color
  matrix.drawPixel(0, 8, matrix.Color(255,255,255)); // x, y, color
  matrix.drawPixel(0, 9, matrix.Color(255,255,255)); // x, y, color
  matrix.drawPixel(0, 10, matrix.Color(255,255,255)); // x, y, color
  matrix.drawPixel(0, 14, matrix.Color(255,255,255)); // x, y, color

  matrix.drawPixel(1, 14, matrix.Color(255,255,255)); // x, y, color
  matrix.drawPixel(1, 13, matrix.Color(255,255,255)); // x, y, color
  matrix.drawPixel(1, 11, matrix.Color(255,255,255)); // x, y, color
  matrix.drawPixel(1, 10, matrix.Color(255,255,255)); // x, y, color
  matrix.drawPixel(1, 9, matrix.Color(255,255,255)); // x, y, color
  matrix.drawPixel(1, 5, matrix.Color(255,255,255)); // x, y, color
  matrix.drawPixel(1, 4, matrix.Color(255,255,255)); // x, y, color
  matrix.drawPixel(1, 3, matrix.Color(255,255,255)); // x, y, color
  matrix.drawPixel(1, 1, matrix.Color(255,255,255)); // x, y, color
  matrix.drawPixel(1, 0, matrix.Color(255,255,255)); // x, y, color
  matrix.show(); // This sends the updated pixel colors to the hardware.

}
/*=========================================================================*/
/*=========================================================================*/

void extinction_progressif(void){

  /******Lumire Blanche *******/
  matrix.drawPixel(0, 0, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(0, 4, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(0, 5, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(0, 6, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(0, 8, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(0, 9, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(0, 10, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(0, 14, matrix.Color(0,0,0)); // x, y, color

  matrix.drawPixel(1, 14, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(1, 13, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(1, 11, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(1, 10, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(1, 9, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(1, 5, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(1, 4, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(1, 3, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(1, 1, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(1, 0, matrix.Color(0,0,0)); // x, y, color
  matrix.show(); // This sends the updated pixel colors to the hardware.

   // Attente de 10 min 
  //delay(60000);
  delay(4000); //  s

  
  /******Lumire Bleue *******/
  matrix.drawPixel(0, 1, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(0, 3, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(0, 7, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(0, 11, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(0, 13, matrix.Color(0,0,0)); // x, y, color

  matrix.drawPixel(1, 12, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(1, 8, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(1, 6, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(1, 2, matrix.Color(0,0,0)); // x, y, color
  matrix.show(); // This sends the updated pixel colors to the hardware.
  
  // Attente de 3 min 
  //delay(18000);
  delay(2000); // 1 s
  
  
  /******Lumire rouge *******/
  matrix.drawPixel(0, 2, matrix.Color(0,0,0)); // x, y, color
  matrix.drawPixel(0,12, matrix.Color(0,0,0)); // x, y, color
  
  matrix.drawPixel(1, 7, matrix.Color(0,0,0)); // x, y, color
  matrix.show(); // This sends the updated pixel colors to the hardware.

 
}
/*=========================================================================*/
// Type    : augmentation = 1 , diminution = 0
/*=========================================================================*/
void modulation_luminosite(int type){

   int pourcentage = 90 ; // pourcentage de changement
   int ancien_val,new_val,delta;
  
  ancien_val= matrix.getBrightness(); 
  delta = (int)((ancien_val * pourcentage) / 100 ); 
  
  switch(type){
    case 0 : 
        new_val = ancien_val - delta ; 
        matrix.setBrightness(new_val);
        break ; 
    case 1:
        new_val = ancien_val + delta ; 
        matrix.setBrightness(new_val);
        break;
     default :
        Serial.print("Action impossible\n\r");
  }

}

Credits

Boisse Martin

Boisse Martin

1 project • 3 followers
Between Paris and New York City. I enjoy resistors, leds and this kind of stuff. Got any question ? Feel free to ask.
Thanks to Rui Santos and B. Aswinth Raj.

Comments