working on it ...

Filters

Explore Public Snippets

Sort by

Found 3,961 snippets

    public by tomsim  1379  2  6  0

    ESP8266 wifi web server setup

    Lambda style Wifi web server with DHT22 data upload to ThingSpeak
    /* DHTServer - ESP8266 Webserver with a DHT sensor as an input
    
       Based on ESP8266Webserver, DHTexample, and BlinkWithoutDelay (thank you)
    
       Version 1.0  5/3/2014  Version 1.0 Mike Barela for Adafruit Industries
    */
    #include <ESP8266WiFi.h>
    #include <WiFiClient.h>
    #include <ESP8266WebServer.h>
    #include <DHT.h>
    #include <TimeLib.h>
    #include "ThingSpeak.h"
    
    #define DHTTYPE DHT22
    
    const int DHTPIN = D4;
    
    const char* ssid     = "mySSID";
    const char* password = "myPassword";
    
    ESP8266WebServer server(80);
    
    /*============ ThingSpeak setup ==================*/
    // Note:  Each channel has its own number and write API key
    // API key is what get used - wrong channel number doesn't matter
    
    // Temperature Humidity Channel
    static unsigned long myChannelNumber = 123456;
    static const char 	*myWriteAPIKey = "AB1CDEF6HIJKLMNO";
    static WiFiClient  client;
    
    /*============ End ThingSpeak setup ==============*/
    
    
    // Initialize DHT sensor 
    // NOTE: For working with a faster than ATmega328p 16 MHz Arduino chip, like an ESP8266,
    // you need to increase the threshold for cycle counts considered a 1 or 0.
    // You can do this by passing a 3rd parameter for this threshold.  It's a bit
    // of fiddling to find the right value, but in general the faster the CPU the
    // higher the value.  The default for a 16mhz AVR is a value of 6.  For an
    // Arduino Due that runs at 84mhz a value of 30 works.
    // This is for the ESP8266 processor on ESP-01 
    DHT dht(DHTPIN, DHTTYPE, 11); // 11 works fine for ESP8266
     
    float lastHumdty, lastTempF;  // Values read from sensor
    static int nextSampleMinute = 15;
    static int minuteSampleInterval = 15;
    
    // Generally, you should use "unsigned long" for variables that hold time
    unsigned long previousMillis = 0;        // will store last temp was read
    const long interval = 2000;              // interval at which to read sensor
    
    void getTemperature() {
      // Wait at least 2 seconds seconds between measurements.
      // if the difference between the current time and last time you read
      // the sensor is bigger than the interval you set, read the sensor
      // Works better than delay for things happening elsewhere also
      unsigned long currentMillis = millis();
     
      if(currentMillis - previousMillis >= interval) {
        // save the last time you read the sensor 
        previousMillis = currentMillis;   
    
        // Reading temperature for humidity takes about 250 milliseconds!
        // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
        lastHumdty = dht.readHumidity();          // Read humidity (percent)
        lastTempF = dht.readTemperature(true);     // Read temperature as Fahrenheit
        // Check if any reads failed and exit early (to try again).
        if (isnan(lastHumdty) || isnan(lastTempF)) {
          Serial.println("Failed to read from DHT sensor!");
          return;
        }
      }
    }
    
    static int uploadData(void)
    {
    	ThingSpeak.setField( 1, lastTempF);
    	ThingSpeak.setField( 2, lastHumdty);
    	int rc = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    //	Serial.println(String("Post rc=")+rc);
    	return rc;
    }
    
     
    const String HTML_TYPE = "text/html";
    
    void handle_null() {
        Serial.println("Handle null");
    	server.send(200,HTML_TYPE,"");
    	delay(100);
    }
    void handleRoot()
    {
    	String wstr = 
    	"<p>Hello from the weather esp8266, read from /temp or /humidity"
    	"<br>set <a href=/set?minuteSampleInterval=5>5 minute</a> sample interval"
    	", <a href=/set?nextSampleMinute=15>sample at 15 </a> minute"
    	"<br>Take <a href=/sample>sample Data</a> and upload to ThingSpeak"
    	"<br><a href=/temp>Get Temperature</a>"
    	"<br><a href=/humidity>Get Humidity</a>";
    	wstr += "<br>Last temperature: " + String(lastTempF)+"F";
    	wstr += " humidity: " + String(lastHumdty)+"%";
    	wstr += "<br>Current minute: " + String(minute(now()));
    	wstr += " next sample time: " + String(nextSampleMinute)+" min.";
    	wstr += " sample interval: " + String(minuteSampleInterval)+" min.";
    	server.send(200,HTML_TYPE, wstr);
    	delay(100);
    }
    void doSample()
    {
    	Serial.println("DoSample");
    	getTemperature();
    	int rc = uploadData();
    	String wstr = "<p>Take sample data:  ";
    	wstr += "<br>Temperature " + String(lastTempF);
    	wstr += "<br>Humidity " + String(lastHumdty);
    	wstr += "<br>Upload thingspeak rc=" + String(rc);
    	server.send(200,HTML_TYPE, wstr);
    }
     
    // Web Server Service Definition structure
    // =======================================
    typedef struct s_WebServiceDef
    {
    	const char *urlName;
    	void (*doit)(void);
    } WebServiceDef;
    
    /* =======================================================================
    	Define web service definition here
    	Each entry has a URL name and a lambda function to service the request
       =======================================================================
    */
    static WebServiceDef wsd[] = {
    	{ "/", handleRoot },
    	{ "/favicon", handle_null },
    	{ "/temp",			// url name
    		[] ()				// lambda function
    		{
    			getTemperature();       // read sensor
    			String wstr="Temperature: "+String((int)lastTempF)+" F";
    			server.send(200, "text/plain", wstr);   // send to someones browser when asked
    		}
    	},
    	{ "/humidity", []()
    		{ 
    			getTemperature();
    			String wstr="Humidity: "+String((int)lastHumdty)+"%";
    			server.send(200, "text/plain", wstr);
    		}
    	},
    	{ "/sample", doSample },
    	{ "/set", []()
    		{
    			String n = String("minuteSampleInterval");
    			if (server.hasArg(n))
    			{
    				int v = server.arg(n).toInt();
    				if (v)
    					minuteSampleInterval = v;
    			}
    			n = String("nextSampleMinute");
    			if (server.hasArg(n))
    			{
    				int v = server.arg(n).toInt();
    				if (v)
    					nextSampleMinute = v;
    			}
    			server.send(200, "text/plain", "ok");
    		}
    	},
     	{0,0}
    };
    
    static void setupServerHandler(void)
    {
    	for (int i; wsd[i].urlName; i++)
    	{
    		server.on( wsd[i].urlName, wsd[i].doit);
    	}
    	server.onNotFound(handleRoot);
    }
    
    static int nextAlarmMin(int sampleInterval)
    {
    	int nextMin = minute(now());
    	nextMin = ((nextMin + sampleInterval) % 60);	// alarm every 5 min
    	return nextMin;
    }
    
    
    
    void setup(void)
    {
    	// You can open the Arduino IDE Serial Monitor window to see what the code is doing
    	Serial.begin(115200);  // Serial connection from ESP-01 via 3.3v console cable
    	dht.begin();           // initialize temperature sensor
    
    	// Connect to WiFi network
    	WiFi.begin(ssid, password);
    	Serial.print("\n\r \n\rWorking to connect");
    
    	// Wait for connection
    	while (WiFi.status() != WL_CONNECTED) {
    	delay(500);
    	Serial.print(".");
    	}
    	Serial.println("");
    	Serial.println("DHT Weather Reading Server");
    	Serial.print("Connected to ");
    	Serial.println(ssid);
    	Serial.print("IP address: ");
    	Serial.println(WiFi.localIP());
    
    	ThingSpeak.begin(client);
    
    	setupServerHandler();
    
    	server.begin();
    	Serial.println("HTTP server started");
    }
     
    void loop(void)
    {
    	int currentMinute = minute(now());
    
    	if (currentMinute == nextSampleMinute)
    	{
    		// trigger sample at set interval
    		Serial.println("Regular sample");
    		getTemperature();
    		int rc = uploadData();
    		Serial.println("rc=" + String(rc));
    
    		nextSampleMinute = nextAlarmMin(minuteSampleInterval);
    		delay(1000);
    	}
    
    	server.handleClient();
    } 
    
    

    public by AbhishekGhosh  201  1  2  1

    5110 Stopwatch

    5110 Stopwatch: watch.ino
    #define PIN_SCE   9
    #define PIN_RESET 10
    #define PIN_DC    12
    #define PIN_SDIN  11
    #define PIN_SCLK  13
    #define LCD_CMD   0
    
    #define LCD_C     LOW
    #define LCD_D     HIGH
    
    #define LCD_X     84
    #define LCD_Y     48
    
    static const byte Digits[][4][18] = 
    {
     {
        { 0xE0, 0xF0, 0xF8, 0xF4, 0xEE, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0xEE, 0xF4, 0xF8, 0xF0, 0xE0 },
        { 0x1F, 0x3F, 0x7F, 0x3F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x7F, 0x3F, 0x1F },  
        { 0xFC, 0xFE, 0xFF, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFE, 0xFF, 0xFE, 0xFC }, 
        { 0x03, 0x07, 0x0F, 0x17, 0x3B, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x3B, 0x17, 0x0F, 0x07, 0x03 },
      },
      {
        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF0, 0xF8, 0xF0, 0xE0 },
        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x7F, 0x3F, 0x1F },  
        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFE, 0xFF, 0xFE, 0xFC }, 
        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0F, 0x07, 0x03 },
      },
      {
        { 0x00, 0x00, 0x00, 0x04, 0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0xEE, 0xF4, 0xF8, 0xF0, 0xE0 },
        { 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xDF, 0xBF, 0x7F, 0x3F, 0x1F },  
        { 0xFC, 0xFE, 0xFF, 0xFE, 0xFD, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00 }, 
        { 0x03, 0x07, 0x0F, 0x17, 0x3B, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x38, 0x10, 0x00, 0x00, 0x00 },
      },
      {
        { 0x00, 0x00, 0x00, 0x04, 0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0xEE, 0xF4, 0xF8, 0xF0, 0xE0 },
        { 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xDF, 0xBF, 0x7F, 0x3F, 0x1F },  
        { 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xFD, 0xFE, 0xFF, 0xFE, 0xFC }, 
        { 0x00, 0x00, 0x00, 0x10, 0x38, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x3B, 0x17, 0x0F, 0x07, 0x03 },
      },
      {
        { 0xE0, 0xF0, 0xF8, 0xF0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF0, 0xF8, 0xF0, 0xE0 },
        { 0x1F, 0x3F, 0x7F, 0xBF, 0xDF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xDF, 0xBF, 0x7F, 0x3F, 0x1F },  
        { 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xFD, 0xFE, 0xFF, 0xFE, 0xFC }, 
        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0F, 0x07, 0x03 },
      },
      {
        { 0xE0, 0xF0, 0xF8, 0xF4, 0xEE, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x04, 0x00, 0x00, 0x00 },
        { 0x1F, 0x3F, 0x7F, 0xBF, 0xDF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00 },  
        { 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xFD, 0xFE, 0xFF, 0xFE, 0xFC }, 
        { 0x00, 0x00, 0x00, 0x10, 0x38, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x3B, 0x17, 0x0F, 0x07, 0x03 },
      },
      {
        { 0xE0, 0xF0, 0xF8, 0xF4, 0xEE, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x04, 0x00, 0x00, 0x00 },
        { 0x1F, 0x3F, 0x7F, 0xBF, 0xDF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00 },  
        { 0xFC, 0xFE, 0xFF, 0xFE, 0xFD, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xFD, 0xFE, 0xFF, 0xFE, 0xFC }, 
        { 0x03, 0x07, 0x0F, 0x17, 0x3B, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x3B, 0x17, 0x0F, 0x07, 0x03 },
      },
      {
        { 0x00, 0x00, 0x00, 0x04, 0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0xEE, 0xF4, 0xF8, 0xF0, 0xE0 },
        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x7F, 0x3F, 0x1F },  
        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFE, 0xFF, 0xFE, 0xFC }, 
        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0F, 0x07, 0x03 },
      },
      {
        { 0xE0, 0xF0, 0xF8, 0xF4, 0xEE, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0xEE, 0xF4, 0xF8, 0xF0, 0xE0 },
        { 0x1F, 0x3F, 0x7F, 0xBF, 0xDF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xDF, 0xBF, 0x7F, 0x3F, 0x1F },  
        { 0xFC, 0xFE, 0xFF, 0xFE, 0xFD, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xFD, 0xFE, 0xFF, 0xFE, 0xFC }, 
        { 0x03, 0x07, 0x0F, 0x17, 0x3B, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x3B, 0x17, 0x0F, 0x07, 0x03 },
      },
      {
        { 0xE0, 0xF0, 0xF8, 0xF4, 0xEE, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0xEE, 0xF4, 0xF8, 0xF0, 0xE0 },
        { 0x1F, 0x3F, 0x7F, 0xBF, 0xDF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xDF, 0xBF, 0x7F, 0x3F, 0x1F },  
        { 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xFD, 0xFE, 0xFF, 0xFE, 0xFC }, 
        { 0x00, 0x00, 0x00, 0x10, 0x38, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x3B, 0x17, 0x0F, 0x07, 0x03 },
      }
    };
    
    static const byte SecondIndicator[4] =
    {
      0x00, 0x07, 0x70, 0x00
    };
    
    void LcdInitialise(void)
    {
      pinMode(PIN_SCE, OUTPUT);
      pinMode(PIN_RESET, OUTPUT);
      pinMode(PIN_DC, OUTPUT);
      pinMode(PIN_SDIN, OUTPUT);
      pinMode(PIN_SCLK, OUTPUT);
      digitalWrite(PIN_RESET, LOW);
      digitalWrite(PIN_RESET, HIGH);
    
      LcdWrite( LCD_CMD, 0x21 ); // LCD Extended Commands.
      LcdWrite( LCD_CMD, 0xC8 ); // Set LCD Vop (Contrast)
      LcdWrite( LCD_CMD, 0x06 ); // Set Temp coefficent
      LcdWrite( LCD_CMD, 0x14 ); // LCD bias mode 1:48
    
      LcdWrite( LCD_CMD, 0x20 ); // LCD Standard Commands.
      LcdWrite( LCD_CMD, 0x0C ); // LCD in normal mode. 0x0d for inverse
    }
    
    void LcdWrite(byte dc, byte data)
    {
      digitalWrite(PIN_DC, dc);
      digitalWrite(PIN_SCE, LOW);
      shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
      digitalWrite(PIN_SCE, HIGH);
    }
    
    void LcdClear(void)
    {
      for (int index = 0; index < LCD_X * LCD_Y / 8; index++)
      {
        LcdWrite(LCD_D, 0x00);
      }
    }
    
    void Spacer()
    {
      LcdWrite(LCD_D, 0x00);
      LcdWrite(LCD_D, 0x00);
    }
    
    void DisplayTime(byte hour, byte minutes, byte seconds)
    {
      byte components[4] = 
      { 
        (byte)(hour / 10), 
        (byte)(hour % 10), 
        (byte)(minutes / 10), 
        (byte)(minutes % 10) 
      };
    
      for(byte row = 0; row < 4; row++)
      {      
        LcdWrite(LCD_C, 0x80 | 0);
        LcdWrite(LCD_C, 0x40 | row);
    
        for(byte digit = 0; digit < 4; digit++)
        {
          for(byte col = 0; col < 18; col++)
          {        
            LcdWrite(LCD_D, Digits[components[digit]][row][col]);
          }      
    
          Spacer();
    
          // Display second indicator after the second digit
          if(digit == 1)
          {
            DisplaySecondIndicator(row, seconds & 0x01);
          }
        }
      }
    
      DrawSecondsBar(seconds);  
    }
    
    void DisplaySecondIndicator(byte row, boolean show)
    {
      for(int secondIndicatorSegment = 0; secondIndicatorSegment < 3; secondIndicatorSegment++)
      {
        if(show)
        {
          LcdWrite(LCD_D, SecondIndicator[row]);
        }
        else // clear
        {
          LcdWrite(LCD_D, 0x00);
        }
      }
      
      Spacer();
    }
    
    void DrawSecondsBar(byte seconds)
    {
      // Position the pointer
      LcdWrite(LCD_C, 0x80 | 0x0b);
      LcdWrite(LCD_C, 0x44);
    
      // Draw the left side of the progress bar box
      LcdWrite(LCD_D, 0xF0);
      
      for(byte i = 0; i < 59; i++)
      {
        if(i < seconds)
        {
          LcdWrite(LCD_D, 0xF0);
        }
        else
        {
          LcdWrite(LCD_D, 0x90);
        }
      }
    
      // Draw the right side of the progress bar box  
      LcdWrite(LCD_D, 0xF0);
    }
    
    byte tcnt2;
    unsigned long time = 0; // 86390000;
    
    void setup(void)
    {
      SetupInterrupt();
      InitializeDisplay();
    }
    
    // Credits for the interrupt setup routine:
    // http://popdevelop.com/2010/04/mastering-timer-interrupts-on-the-arduino/
    void SetupInterrupt()
    {
      /* First disable the timer overflow interrupt while we're configuring */  
      TIMSK2 &= ~(1<<TOIE2);   
    
      /* Configure timer2 in normal mode (pure counting, no PWM etc.) */  
      TCCR2A &= ~((1<<WGM21) | (1<<WGM20));   
      TCCR2B &= ~(1<<WGM22);   
      
      /* Select clock source: internal I/O clock */  
      ASSR &= ~(1<<AS2);
         
      /* Disable Compare Match A interrupt enable (only want overflow) */  
      TIMSK2 &= ~(1<<OCIE2A);   
      
      /* Now configure the prescaler to CPU clock divided by 128 */  
      TCCR2B |= (1<<CS22)  | (1<<CS20); // Set bits   
      TCCR2B &= ~(1<<CS21);             // Clear bit   
      
      /* We need to calculate a proper value to load the timer counter.  
       * The following loads the value 131 into the Timer 2 counter register  
       * The math behind this is:  
       * (CPU frequency) / (prescaler value) = 125000 Hz = 8us.  
       * (desired period) / 8us = 125.  
       * MAX(uint8) + 1 - 125 = 131;  
       */  
      /* Save value globally for later reload in ISR */  
      tcnt2 = 131;    
         
      /* Finally load end enable the timer */  
      TCNT2 = tcnt2;   
      TIMSK2 |= (1<<TOIE2);   
    }
    
    void InitializeDisplay()
    {
      LcdInitialise();
      LcdClear();
    }
    
    /*  
     * Install the Interrupt Service Routine (ISR) for Timer2 overflow.  
     * This is normally done by writing the address of the ISR in the  
     * interrupt vector table but conveniently done by using ISR()  */  
    ISR(TIMER2_OVF_vect) {   
      /* Reload the timer */  
      TCNT2 = tcnt2;
      
      time++;
      time = time % 86400000; 
    }   
    
    void loop(void)
    {
      unsigned long t = (unsigned long)(time/1000);
      
      DisplayTime((byte)(t / 3600), (byte)((t / 60) % 60), (byte)(t % 60));
    }
    
    

    public by AbhishekGhosh  221  0  3  0

    Arduino 7 Segment 4 Digit clock

    Arduino 7 Segment 4 Digit clock: clock.ino
    #include <Wire.h>
    #include "TM1637.h"  // http://www.seeedstudio.com/wiki/File:DigitalTube.zip
    
        // 7сигментный индикатор
    #define CLK 6         
    #define DIO 7 
    #define brightness 6  // яркость, от 0 до 7
    
        // кнопки
    #define keyHor 5
    #define keyMin 4 
    #define keyPL  3
    
    TM1637 tm1637(CLK,DIO);  
    #define DS3231_I2C_ADDRESS 0x68
      
    volatile boolean flag;
    
    ///// часы ..
    byte decToBcd(byte val){
      return ( (val/10*16) + (val%10) );
    }
    
    byte bcdToDec(byte val){
      return ( (val/16*10) + (val%16) );
    }
    
    void setDateDs3231(byte second,        // 0-59
                       byte minute,        // 0-59
                       byte hour,          // 1-23
                       byte dayOfWeek,     // 1-7
                       byte dayOfMonth,    // 1-28/29/30/31
                       byte month,         // 1-12
                       byte year)          // 0-99
    {
       Wire.beginTransmission(DS3231_I2C_ADDRESS);
       Wire.write(0);
       Wire.write(decToBcd(second));    
       Wire.write(decToBcd(minute));
       Wire.write(decToBcd(hour));     
       Wire.write(decToBcd(dayOfWeek));
       Wire.write(decToBcd(dayOfMonth));
       Wire.write(decToBcd(month));
       Wire.write(decToBcd(year));
       Wire.endTransmission();
    }
    
    void getDateDs3231(byte *second,
              byte *minute,
              byte *hour,
              byte *dayOfWeek,
              byte *dayOfMonth,
              byte *month,
              byte *year)
    {
    
      Wire.beginTransmission(DS3231_I2C_ADDRESS);
      Wire.write(0);
      Wire.endTransmission();
    
      Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
    
      *second     = bcdToDec(Wire.read() & 0x7f);
      *minute     = bcdToDec(Wire.read());
      *hour       = bcdToDec(Wire.read() & 0x3f); 
      *dayOfWeek  = bcdToDec(Wire.read());
      *dayOfMonth = bcdToDec(Wire.read());
      *month      = bcdToDec(Wire.read());
      *year       = bcdToDec(Wire.read());
    }
    
    void setINT(){    //включает выход SQW, который вроде выключен по умолчанию
      Wire.beginTransmission(DS3231_I2C_ADDRESS);
      Wire.write(0x0E);
      Wire.write(0x0);
      Wire.endTransmission();
    }
    
    void blink() {
      digitalWrite(13, !digitalRead(13));
      flag = !flag;
      tm1637.point(flag); 
    }
    
    void setup() {
    //  Serial.begin(9600);
      Wire.begin();
      pinMode(13, OUTPUT);
      pinMode(keyHor, INPUT_PULLUP);
      pinMode(keyMin, INPUT_PULLUP);
      pinMode(keyPL, INPUT_PULLUP);
    
      tm1637.init();
      tm1637.set(brightness);  
      
      setINT(); 
      attachInterrupt(0, blink, CHANGE);
    }
    
    void loop(){
        // читаем время из модуля
      byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; 
      getDateDs3231(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); 
        // забиваем массив значениями для отпарвки на экран
      int8_t TimeDisp[4]; 
      
      TimeDisp[0] = hour / 10;
      TimeDisp[1] = hour % 10;
      TimeDisp[2] = minute / 10;
      TimeDisp[3] = minute % 10;
    
        // обработка кнопок
      if (!digitalRead(keyHor) && !digitalRead(keyPL)){   // часы
          second = 0;                           // сбрасываем секунды
          hour++;                               // пребавляем единицу к часам
          if (hour > 23) hour = 0;              // если вылезли за границы присваеваем 0
          setDateDs3231(second, minute, hour, dayOfWeek, dayOfMonth, month, year); // пишим в модуль
          delay(200);
      }
      if (!digitalRead(keyMin) && !digitalRead(keyPL)){   // минуты
          second = 0;
          minute++;
          if (minute > 59) minute = 0;
          setDateDs3231(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
          delay(200);
      }
         // отправляем массив на экран
      tm1637.display(TimeDisp);
     
      
    }
    
    
    

    public by AnthonyKelly  13394  24  6  0

    Heating Control Spark Core

    SYSTEM_MODE(SEMI_AUTOMATIC);
    
    //State : 0=Heat OFF ; 1=Heat ON;
    // 2=Heat Turning OFF; 3 = Heat Water
    int State = 0;
    
    int button = 0;
    int button_prev = 0;
    
    bool ONCondPrev = 0;
    bool ONCond = 0;
    
    int lastSync = 0;
    int Timing = 0;
    int Heating = 0;
    int OFFTimer = 0;
    int ONHour = 06;
    int ONMinute = 00;
    int tempDOWNInt = 0;
    int tempOUTInt = 0;
    int tempWATERInt = 0;
    int setpointInt = 0;
    
    float setpoint = 0;
    float setpointDOWN = 20.5;
    float setWater = 40;
    float tempDOWN = 0;
    float tempOUT = 0;
    float tempWATER = 0;
    float tempPot = 0;
    float  EPS = 0.3;
    
    char resultstr[64];
    
    void setup() {
        Spark.function("SetVal",set_val);
        Spark.variable("tempDOWN", &tempDOWNInt, INT);
        Spark.variable("tempOUT", &tempOUTInt, INT);
        Spark.variable("tempWATER", &tempWATERInt, INT);
        Spark.variable("State", &State, INT);
        Spark.variable("Setpoint", &setpointInt, INT);
        Spark.variable("Timing", &Timing, INT);
        Spark.variable("Heating", &Heating, INT);
        Spark.variable("result", &resultstr, STRING); 
        
        lastSync = Time.now();
        
        pinMode(D0, OUTPUT); // Heat Control
        pinMode(D1, OUTPUT); // Upstairs Rads Control
        pinMode(D2, OUTPUT); // Downstairs Rads Control
        pinMode(D3, OUTPUT); // Heat LED
        pinMode(D4, OUTPUT); // Upstairs Rads LED
        pinMode(D5, OUTPUT); // Downstairs Rads LED
        
        pinMode(A0, INPUT); // TEMP Sensor 0
        pinMode(A1, INPUT); // TEMP Sensor 1
        pinMode(A2, INPUT); // TEMP Sensor 2
        
        pinMode(D6, INPUT); // Push Button
        pinMode(A4, INPUT); // Potentiometer
        
        pinMode(A5, OUTPUT); // LED BLUE
        pinMode(A6, OUTPUT); // LED GREEN
        pinMode(A7, OUTPUT); // LED RED
        
        State = 0;
        ONCond = 1;
        Time.zone(1);  // GMT +/-
        
        // Connect to Cloud Unless Button is Pressed on Startup
        if(!digitalRead(D6)) Spark.connect();
    }
    
    void loop() {
        sprintf(resultstr, "{\"data1\":%d,\"data2\":%d,\"data3\":%d,\"data4\":%d}", tempDOWNInt, tempWATERInt, tempOUTInt, State); 
        
        // Sync Time?
        if(Time.now() > lastSync+86400) {
            Spark.syncTime();
            lastSync = Time.now();
        }
        
        // Update Button State
        delay(100);
        button_prev = button;
        button = digitalRead(D6);
        
        // Read Temperatures
        // LM35
        tempDOWN = 0.02*(analogRead(A0)*330.0/4095-2) + 0.98*tempDOWN;
        tempDOWNInt = int(tempDOWN*10);  // Report to 1 decimal place
        // TMP36
        tempWATER = 0.02*(analogRead(A1)*3.3/4095-0.5)*100 + 0.98*tempWATER;
        tempWATERInt = int(tempWATER*10);  // Report to 1 decimal place
        // TMP36
        tempOUT = 0.02*(analogRead(A2)*3.3/4095-0.5)*100 + 0.98*tempOUT;
        tempOUTInt = int(tempOUT*10);  // Report to 1 decimal place
        
        // Read Potentiometer
        tempPot = 0.1*map(analogRead(A4),0,4096,15,25 )+ 0.9*tempPot;
        if (tempPot > setpointDOWN) setpoint = tempPot;
        else setpoint = setpointDOWN;
        setpointInt = int(setpoint*10);  // Report to 1 decimal place
        
        // OFF Timer
        if (Timing && Time.now()>OFFTimer) {
            Timing = 0;
            State = 0;
        }
        
        // ON Timer
        ONCondPrev = ONCond;
        ONCond = Time.hour() >= ONHour && Time.minute() >= ONMinute;
        if (!ONCondPrev && ONCond) {
            State = 3;
        }
        
        switch(State) {
            case 0: { // Heat OFF
                digitalWrite(D0,LOW); // Heat OFF
                digitalWrite(D3,LOW); // Heat LED OFF
                digitalWrite(D1,LOW); // Upstairs Rads OFF
                digitalWrite(D4,LOW); // Upstairs Rads LED OFF
                digitalWrite(D2,LOW); // Downstairs Rads OFF
                digitalWrite(D5,LOW); // Downstairs Rads LED OFF
                Heating = 0;
                // BLUE LED
                analogWrite(A5,255);
                analogWrite(A6,0);
                analogWrite(A7,0);
                
                // Button press?
                if (!button_prev && button) {
                    delay(20);
                    if (digitalRead(D6)) State = 1;  // Short Press
                    delay(1000);
                    if (digitalRead(D6)) State = 3; // Long Press
                }
                break;
            }
            case 1: { // Heat ON
                digitalWrite(D0,HIGH);// Heat ON
                digitalWrite(D3,HIGH); // Heat LED ON
                if (tempDOWN <= setpoint)  {// s/b tempUP!!! <<<<<<<<<
                    digitalWrite(D1,HIGH); // Upstairs Rads ON
                    digitalWrite(D4,HIGH); // Upstairs Rads LED ON
                    // RED LED
                    analogWrite(A5,0);
                    analogWrite(A6,0);
                    analogWrite(A7,255);
                    Heating = 1;
                }
                if (tempDOWN >= setpoint+EPS)  {// s/b tempUP!!! <<<<<<<<<
                    digitalWrite(D1,LOW); // Upstairs Rads OFF
                    digitalWrite(D4,LOW); // Upstairs Rads LED OFF
                    // MAGENTA LED
                    analogWrite(A5,255);
                    analogWrite(A6,0);
                    analogWrite(A7,255);
                    Heating = 0;
                }
                if (tempDOWN <= setpoint)  {
                    digitalWrite(D2,HIGH); // Downstairs Rads ON
                    digitalWrite(D5,HIGH); // Downstairs Rads LED ON
                    // RED LED
                    analogWrite(A5,0);
                    analogWrite(A6,0);
                    analogWrite(A7,255);
                    Heating = 1;
                }
                if (tempDOWN >= setpoint+EPS)  {
                    digitalWrite(D2,LOW); // Downstairs Rads OFF
                    digitalWrite(D5,LOW); // Downstairs Rads LED OFF
                    // MAGENTA LED
                    analogWrite(A5,255);
                    analogWrite(A6,0);
                    analogWrite(A7,255);
                    Heating = 0;
                }
                // Button press?
                if (!button_prev && button) {
                    delay(20);
                    if (digitalRead(D6)) State = 2;  // Short Press
                    delay(1000);
                    if (digitalRead(D6)) State = 3; // Long Press
                }
                break;
            }
                case 2: { // Heat Turning OFF
                digitalWrite(D0,LOW); // Heat OFF
                digitalWrite(D3,LOW); // Heat LED OFF
                digitalWrite(D1,HIGH); // Upstairs Rads ON
                digitalWrite(D4,HIGH); // Upstairs Rads LED ON
                digitalWrite(D2,HIGH); // Downstairs Rads ON
                digitalWrite(D5,HIGH); // Downstairs Rads LED ON
                Heating = 0;
                // BLUE LED
                analogWrite(A5,255);
                analogWrite(A6,0);
                analogWrite(A7,0);
                
                if (Timing == 0) {
                    OFFTimer = Time.now()+1800; // Timer expires 30min from now
                    Timing = 1;
                }
                
                // Button press?
                if (!button_prev && button) {
                    delay(20);
                    if (digitalRead(D6)) {
                        State = 1;  // Short Press
                        Timing = 0;
                    }
                    delay(1000);
                    if (digitalRead(D6)) {
                        State = 0; // Long Press
                        Timing = 0;
                    }
                }
                break;
            }
                case 3: { // Heat Water
                if (tempWATER <= setWater) {
                    digitalWrite(D0,HIGH); // Heat ON
                    digitalWrite(D3,HIGH); // Heat LED ON
                    digitalWrite(D1,LOW); // Upstairs Rads OFF
                    digitalWrite(D4,LOW); // Upstairs Rads LED OFF
                    digitalWrite(D2,LOW); // Downstairs Rads OFF
                    digitalWrite(D5,LOW); // Downstairs Rads LED OFF
                    // GREEN LED
                    analogWrite(A5,0);
                    analogWrite(A6,255);
                    analogWrite(A7,0);
                    // Set Timer
                    if (!Timing) {
                    OFFTimer = Time.now()+7200; // Timer expires 120min from now
                    Timing = 1;
                    }
                }
                else {
                    // Cancel Timer
                    Timing = 0;
                    // Turn off
                    State = 0;
                }
                Heating = 0;
                
                // Button press?
                if (!button_prev && button) {
                    delay(20);
                    if (digitalRead(D6)) {
                        State = 1;  // Short Press
                        Timing = 0;
                    }
                    delay(1000);
                    if (digitalRead(D6)) {
                        State = 0; // Long Press
                        Timing = 0;
                    }
                }
                break;
            }
        }
    }
    
    int set_val(String command)
    {
        int entryState = State;
        
        if(command.substring(0,6) == "STATE:") {  // "STATE:0"
            State = (command.charAt(6) - '0');
            return 1;
        }
        else if (command.substring(0,8) == "SETDOWN:") {  // "SETDOWN:18.5"
            setpointDOWN = 10*(command.charAt(8) - '0')+(command.charAt(9) - '0')+0.1*(command.charAt(11) - '0');
            return 1;
        }
        else return -1;
        // Cancel Timers if necessary
        if(Timing && entryState!=State) Timing=0;
    }

    external by thexmanxyz  2  0  1  0

    Arduino - SD.h / Ethernet.h - Buffered file read / write

    Arduino - SD.h / Ethernet.h - Buffered file read / write: SD-Ethernet-Buffered-Read-Write
    int bufferSize = 64; // buffer size you want to use
    while(file.available()) // file you previously pointed at
    {
        char buffer[bufferSize];
        memset(buffer, '\n', bufferSize); // don't forget to fill the buffer with \n to prevent errors on last buffer read
        file.read(&buffer, bufferSize); // read from file
        client->write(buffer, bufferSize); // write to client
    }
    
    

    external by PRNicovich  11  2  1  0

    Arduino Code for DAC8568

    Arduino Code for DAC8568: DAC8568-Arduino
    /*
    DAC8568
    http://www.mouser.com/ds/2/405/sbas430d-94281.pdf
    
    Vout = (Din/(2^n))*Vref*Gain
    Din is straight binary
    0 <= Din <= 65535
    n = 16
    Gain = 2 
    => Vout = (Din/65536)*Vref*2
    Internal reference must be enable (disabled by default)
    
    Two modes of operation, static and flexible
    In flexible mode, to always have internal reference powered on, write the following to DB register (32 bit)
    0b0XXX1001XXXX101XXXXXXXXXXXXXXXXX  
    
    Data Input Register
    0b     0XXX             XXXX            XXXX       XXXX XXXX XXXX XXXX         XXXX
       Prefix Bits(4) Control Bits(4)  Addr. Bits (4)     Data Bits (16)     Feature Bits (4)
    */
    #include <SPI.h>
    
    const int syncPin = 10;
    const unsigned int setVrefOut1 = 0b00001001; 
    const unsigned int setVrefOut2 = 0b00001010;
    const unsigned int setVrefOut3 = 0b00000000; 
    const unsigned int setVrefOut4 = 0b00000000; 
    unsigned int prefix = 0b0000; //shouldn't change
    unsigned int control = 0b0011; //0b0010 = write and update all registers, 0b0011 write and update single register
    unsigned int address = 0b0000; //channel A = 0b0000
    unsigned int data = 0b0101101001011010;
    unsigned int feature = 0b0000;
    //long output = 0b00000000000000000000000000000000;
    unsigned int one;
    unsigned int two;
    unsigned int three;
    unsigned int four;
    
    void setup() {
      // set the slaveSelectPin as an output:
      pinMode (syncPin, OUTPUT);
      // initialize SPI:
      SPI.setDataMode(SPI_MODE1);
      SPI.begin();
      delay(20);
      digitalWrite(syncPin,LOW);
      SPI.transfer(setVrefOut1);
      SPI.transfer(setVrefOut2); 
      SPI.transfer(setVrefOut3); 
      SPI.transfer(setVrefOut4); 
      digitalWrite(syncPin,HIGH);
    }
    
    void loop() {
      data = 0b1111111111111111;
      for (unsigned int address = 0; address<8; address++)
      {
      DAC8568Write(prefix, control, address, data, feature);
      delay(1000);
      }
      data = 0b0111111111111111;
      for (unsigned int address = 0; address<8; address++)
      {
      DAC8568Write(prefix, control, address, data, feature);
      delay(1000);
      }
      data = 0b0000000000000000;
      for (unsigned int address = 0; address<8; address++)
      {
      DAC8568Write(prefix, control, address, data, feature);
      delay(1000);
      }
    }
    
    void DAC8568Write(unsigned int prefix, unsigned int control, unsigned int address, unsigned int data, unsigned int feature) {
      // take the SS pin low to select the chip:
      
      //  send in the address and value via SPI:
      one = (prefix << 4)|control;
      two = (address << 4)|(data >>12);
      three = data >> 4;
      four = (data << 4)|feature;
      //output = (one<<24)|(two<<16)|(three<<8)|four;
      digitalWrite(syncPin,LOW);
      SPI.transfer(one);
      SPI.transfer(two);
      SPI.transfer(three);
      SPI.transfer(four);
      //SPI.transfer(address);
      //SPI.transfer(value);
      // take the SS pin high to de-select the chip:
      digitalWrite(syncPin,HIGH); 
    }
    
    
    

    external by Ceiborg  5  0  1  0

    lcd keypad shield :: hello world :: arduino uno

    lcd keypad shield :: hello world :: arduino uno: lcd keypad shield :: hello world
    /*
      LiquidCrystal Library - Hello World
    
     Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
     library works with all LCD displays that are compatible with the
     Hitachi HD44780 driver. There are many of them out there, and you
     can usually tell them by the 16-pin interface.
    
     This sketch prints "Hello World!" to the LCD
     and shows the time.
    
      The circuit:
     * LCD RS pin to digital pin 12
     * LCD Enable pin to digital pin 11
     * LCD D4 pin to digital pin 5
     * LCD D5 pin to digital pin 4
     * LCD D6 pin to digital pin 3
     * LCD D7 pin to digital pin 2
     * LCD R/W pin to ground
     * LCD VSS pin to ground
     * LCD VCC pin to 5V
     * 10K resistor:
     * ends to +5V and ground
     * wiper to LCD VO pin (pin 3)
    
     Library originally added 18 Apr 2008
     by David A. Mellis
     library modified 5 Jul 2009
     by Limor Fried (http://www.ladyada.net)
     example added 9 Jul 2009
     by Tom Igoe
     modified 22 Nov 2010
     by Tom Igoe
     modified 7 Nov 2016
     by Arturo Guadalupi
    
     This example code is in the public domain.
    
     http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld
    
    */
    
    // include the library code:
    #include <LiquidCrystal.h>
    
    // initialize the library by associating any needed LCD interface pin
    // with the arduino pin number it is connected to
    const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
    LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
    
    void setup() {
      // set up the LCD's number of columns and rows:
      lcd.begin(16, 2);
      // Print a message to the LCD.
      lcd.print("hello, world!");
    }
    
    void loop() {
      // set the cursor to column 0, line 1
      // (note: line 1 is the second row, since counting begins with 0):
      lcd.setCursor(0, 1);
      // print the number of seconds since reset:
      lcd.print(millis() / 1000);
    }
    
    

    external by akib hosen khan  3  0  1  0

    configure Bluetooth module with arduino UNO

    configure Bluetooth module with arduino UNO: for HC_01, HC-05, HC-06
    /*
    
    AUTHOR: akib hosen khan
    LICENSE: Public domain (use at your own risk)
    CONTACT: twitter.com/akibhosenkhan
    
    */
    
    
    #include <SoftwareSerial.h>
    
    SoftwareSerial BTSerial(10, 11); // RX | TX
    
    void setup() 
    {
      pinMode(9, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
      digitalWrite(9, HIGH); 
      Serial.begin(9600);
      Serial.println("Enter AT commands:");
      BTSerial.begin(9600);  // HC-05 default speed in AT command more
    }
    
    void loop()
    {
    
      // Keep reading from HC-05 and send to Arduino Serial Monitor
      if (BTSerial.available())
        Serial.write(BTSerial.read());
    
      // Keep reading from Arduino Serial Monitor and send to HC-05
      if (Serial.available())
        BTSerial.write(Serial.read());
    }
    
    
    

    external by Kemal IKIZOGLU  13  0  1  0

    Arduino RGB Led Kullanımı - Karma Renkler

    Arduino RGB Led Kullanımı - Karma Renkler: Arduino RGB Led Kullanımı - Karma Renkler
    // ************************
    // **   Kemal İKİZOĞLU   **
    // ************************
    
    int kirmiziPin= 10;
    int yesilPin = 8;
    int maviPin = 9;
    
    void setup() {
      pinMode(kirmiziPin, OUTPUT);
      pinMode(yesilPin, OUTPUT);
      pinMode(maviPin, OUTPUT);
    }
    void loop() {
      setColor(255, 255, 255); // Beyaz
      delay(1000);
      setColor(170, 0, 255); // Mor
      delay(1000);
      setColor(255, 255, 0);  // Sarı
      delay(1000);  
      setColor(0, 255, 255);  // Açık Mavi
      delay(1000);
      setColor(128, 255, 0);  // Açık Yeşil
      delay(1000);
      setColor(128, 0, 0); // Maroon
      delay(1000);
      setColor(0, 0, 128); // Lila
      delay(1000);
      }
    void setColor(int redValue, int greenValue, int blueValue) {
      analogWrite(kirmiziPin, redValue);
      analogWrite(yesilPin, greenValue);
      analogWrite(maviPin, blueValue);
    }
    
    

    external by shahrulnizam  7  0  1  0

    Arduino Project: Button Switch

    Arduino Project: Button Switch: Arduino Button Switch
    /*
    Project: Button Switch
    Programmer: Shahrulnizam Mat Rejab
    Board: Arduino UNO
    Last Modified: 18 February 2018
    Website: http://shahrulnizam.com
    */
    
    #define SW1           7
    #define SW2           6
    #define SW3           5
    #define SW4           4
    #define RELAY1        11
    #define RELAY2        10
    #define RELAY3        9
    #define RELAY4        8
    
    void setup()
    {
      pinMode(SW1,INPUT_PULLUP);
      pinMode(SW2,INPUT_PULLUP);
      pinMode(SW3,INPUT_PULLUP);
      pinMode(SW4,INPUT_PULLUP);
      pinMode(RELAY1,OUTPUT);
      pinMode(RELAY2,OUTPUT);
      pinMode(RELAY3,OUTPUT);
      pinMode(RELAY4,OUTPUT);
      digitalWrite(RELAY1,LOW);
      digitalWrite(RELAY2,LOW);
      digitalWrite(RELAY3,LOW);
      digitalWrite(RELAY4,LOW);
    }
    
    void loop()
    {
      if(digitalRead(SW1)==0)
      {
        digitalWrite(RELAY1,!digitalRead(RELAY1));
        delay(200);
        while(digitalRead(SW1)==0) continue;
      }
    
      if(digitalRead(SW2)==0)
      {
        digitalWrite(RELAY2,!digitalRead(RELAY2));
        delay(200);
        while(digitalRead(SW2)==0) continue;
      }
    
      if(digitalRead(SW3)==0)
      {
        digitalWrite(RELAY3,!digitalRead(RELAY3));
        delay(200);
        while(digitalRead(SW3)==0) continue;
      }
    
      if(digitalRead(SW4)==0)
      {
        digitalWrite(RELAY4,!digitalRead(RELAY4));
        delay(200);
        while(digitalRead(SW4)==0) continue;
      }      
    }
    
    
    
    • Public Snippets
    • Channels Snippets