This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ตัวอย่างโค้ดสำหรับการใช้งาน TCS3200 Sensor บน ESP32 | |
* พร้อมการปรับเทียบเซ็นเซอร์เพื่อให้สามารถอ่านค่าสีได้อย่างแม่นยำ | |
* | |
* วิธีการต่อสาย: | |
* | ESP32 Pin | TCS3200 Pin | | |
* |------------|-------------| | |
* | 3.3v | Vcc | | |
* | GND | GND | | |
* | 3.3v | LED | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define TCS34725_ADDRESS 0x29 | |
#define TCS34725_COMMAND_BIT 0x80 | |
SoftI2C SoftWire1(25, 26); | |
SoftI2C SoftWire2(27, 14); | |
// Assume S0 goes HIGH, S1 goes LOW | |
#define S2 26 /*Define S2 Pin Number of ESP32*/ | |
#define S3 25 /*Define S3 Pin Number of ESP32*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#define S2 26 /*Define S2 Pin Number of ESP32*/ | |
#define S3 25 /*Define S3 Pin Number of ESP32*/ | |
#define sensorOut 14 /*Define Sensor Output Pin Number of ESP32*/ | |
/*Define int variables*/ | |
int Red = 0; | |
int Green = 0; | |
int Blue = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void loop() { | |
digitalWrite(LED_BUILTIN, HIGH); | |
delay(1000); | |
digitalWrite(LED_BUILTIN, LOW); | |
delay(1000); | |
} | |
unsigned long previousMillis = 0; | |
bool ledState = false; | |
const long interval = 1000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ปัญหา: ปุ่มกดไม่ไว | |
void loop() { | |
delay(5000); // หยุด 5 วินาที | |
if (digitalRead(buttonPin) == HIGH) { | |
// ปุ่มอาจถูกกดและปล่อยไปแล้วระหว่าง delay() | |
Serial.println("Button pressed"); // อาจไม่ทำงาน | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ตัวอย่างปัญหาของ delay() | |
void loop() { | |
digitalWrite(LED_BUILTIN, HIGH); | |
delay(1000); // หยุดทำงานทุกอย่าง 1 วินาที! | |
digitalWrite(LED_BUILTIN, LOW); | |
delay(1000); // หยุดอีก 1 วินาที | |
// ในขณะ delay() โปรแกรมไม่สามารถ: | |
// - อ่านเซนเซอร์ | |
// - ตรวจสอบปุ่มกด |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef __BATTERY_H__ | |
#define __BATTERY_H__ | |
#include <Arduino.h> | |
// ADC Configuration | |
#define BATTERY_PIN 34 // GPIO34 = ADC1_CH6 | |
#define VOLTAGE_DIVIDER_RATIO 2.0 // 47kΩ / (47kΩ + 47kΩ) = 0.5 (so 1/0.5 = 2.0) | |
#define ADC_SAMPLES 20 // Must be odd number for true median | |
#define VOLTAGE_OFFSET 0.2463 // Offset for calibration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* -------------------------------------------------------------------------- */ | |
/* ModuleMore RS-LDO-N01-1 (Modbus) Example code */ | |
/* -------------------------------------------------------------------------- */ | |
/* ------------------------------- วิธีการต่อ ------------------------------- */ | |
/** | |
| ESP32 | 12V Adapter | MAX485 | DO RS485 | | |
|-------|-------------|--------|----------| | |
| GND | GND | GND | Black | | |
| 3.3V | | VCC | | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
/* Get all possible data from MPU6050 | |
* Accelerometer values are given as multiple of the gravity [1g = 9.81 m/s²] | |
* Gyro values are given in deg/s | |
* Angles are given in degrees | |
* Note that X and Y are tilt angles and not pitch/roll. | |
* | |
* License: MIT | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <SoftwareSerial.h> | |
#include <TinyGPSPlus.h> | |
EspSoftwareSerial::UART gpsSerial; | |
TinyGPSPlus gps; | |
static void smartDelay(unsigned long ms); |
NewerOlder