Arduino Preference ESP8266 ESP32

Additional Boards Manager URLs https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json

millis() ใน arduino

แบบที่ 1 unsigned long period = 1000; //ระยะเวลาที่ต้องการรอ unsigned long last_time = 0; //ประกาศตัวแปรเป็น global เพื่อเก็บค่าไว้ไม่ให้ reset จากการวนloop void setup() { Serial.begin(115200); } void loop() { if( millis() – last_time > period) { last_time = millis(); //เซฟเวลาปัจจุบันไว้เพื่อรอจนกว่า millis() จะมากกว่าตัวมันเท่า period Serial.println(“Hello arduinona!”); } } ขอบคุณ: https://www.modulemore.com/article/3/%E0%B8%A5%E0%B8%94%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%8A%E0%B9%89-delay-%E0%B8%AB%E0%B8%B1%E0%B8%99%E0%B8%A1%E0%B8%B2%E0%B9%83%E0%B8%8A%E0%B9%89-millis-%E0%B8%81%E0%B8%B1%E0%B8%99%E0%B8%94%E0%B8%B5%E0%B8%81%E0%B8%A7%E0%B9%88%E0%B8%B2 แนวที่ 2 int period = 1000; unsigned long time_now = … Read more

NodeMCU ESP8266 TM1637 NTP DHT11

NODEMCU ESP8266 4 Digit Seven Segment TM1637 DHT11 SevenSegmentTM1637.h #include <NTPClient.h> #include <ESP8266WiFi.h> #include <WiFiUdp.h> #include “SevenSegmentTM1637.h” #include “SevenSegmentExtended.h” #include <DHT.h> #define CLK D2 // Define the connections pins: #define DIO D3 #define DHTPIN D5 // Pin sensor is connected to char cdmy[11]; // Set DHT type, uncomment whatever type you’re using! #define DHTTYPE DHT11 … Read more

TM1637.h Groove

#include “TM1637.h” TM1637 tm1637(CLK, DIO); tm1637.set(); tm1637.init(); tm1637.set(BRIGHTEST);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7; tm1637.clearDisplay(); // clear the display tm1637.displayStr();  tm1637.displayStr(‘ABCD’);  // Without specifying decimal pointt it displays int tm1637.displayNum(num); // Colon light up as decimal point tm1637.displayNum(num, 2); delay(2000); // Note that adding 3 digits (-123450) makes number out of int range tm1637.displayNum(num, 3); … Read more

Arduino C TM structure

struct tm *ptm = gmtime ((time_t *)&epochTime); int monthDay = ptm->tm_mday; sprintf(cdmy,” %02d-%02d-%02d “,ptm->tm_mday,ptm->tm_mon+1,ptm->tm_year+2443); sprintf(chm,”%02d%02d”,ptm->tm_hour,ptm->tm_min); Member Type Meaning Range tm_sec int seconds after the minute 0-61* tm_min int minutes after the hour 0-59 tm_hour int hours since midnight 0-23 tm_mday int day of the month 1-31 tm_mon int months since January 0-11 tm_year int years … Read more

ESP8266 NODEMCU TM1637 NTP

#include <NTPClient.h> #include <ESP8266WiFi.h> #include <WiFiUdp.h> #include <TM1637Display.h> // #define CLK D2 // Define the connections pins: #define DIO D3 TM1637Display display = TM1637Display(CLK, DIO); // Create display object of type TM1637Display: const char *ssid = “XXXX”; const char *password = “xxxxx”; //const long utcOffsetInSeconds = 19802; const long utcOffsetInSeconds = 25200; // Define NTP … Read more

NODEMCU 4DIGIT TM1637 DHT11

#include <NTPClient.h> #include <ESP8266WiFi.h> #include <WiFiUdp.h> #include <TM1637Display.h> // #include <DHT.h> #define CLK D2 // Define the connections pins: #define DIO D3 #define DHTPIN D5 // Pin sensor is connected to // Create degree Celsius symbol: const uint8_t celsius[] = { // SEG_A | SEG_B | SEG_F | SEG_G, // Circle SEG_G | SEG_E | … Read more