Skip to content

Instantly share code, notes, and snippets.

View fxprime's full-sized avatar

ArduinoNa ขายอุปกรณ์ Arduino, เครื่องมือช่าง, raspberry pi, สอน ROS fxprime

View GitHub Profile
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;
// ปัญหา: ปุ่มกดไม่ไว
void loop() {
delay(5000); // หยุด 5 วินาที
if (digitalRead(buttonPin) == HIGH) {
// ปุ่มอาจถูกกดและปล่อยไปแล้วระหว่าง delay()
Serial.println("Button pressed"); // อาจไม่ทำงาน
}
}
// ตัวอย่างปัญหาของ delay()
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000); // หยุดทำงานทุกอย่าง 1 วินาที!
digitalWrite(LED_BUILTIN, LOW);
delay(1000); // หยุดอีก 1 วินาที
// ในขณะ delay() โปรแกรมไม่สามารถ:
// - อ่านเซนเซอร์
// - ตรวจสอบปุ่มกด
@fxprime
fxprime / battery.h
Created April 21, 2025 06:38
MEMO PROJECT (DROWSINESS DETECTOR DEVICE)
#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
@fxprime
fxprime / ESP32_MAX485_DO_SENSOR.ino
Created March 30, 2025 05:26
ModuleMore RS-LDO-N01-1 (Modbus) Example code
/* -------------------------------------------------------------------------- */
/* ModuleMore RS-LDO-N01-1 (Modbus) Example code */
/* -------------------------------------------------------------------------- */
/* ------------------------------- วิธีการต่อ ------------------------------- */
/**
| ESP32 | 12V Adapter | MAX485 | DO RS485 |
|-------|-------------|--------|----------|
| GND | GND | GND | Black |
| 3.3V | | VCC | |
#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
*/
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <TinyGPSPlus.h>
EspSoftwareSerial::UART gpsSerial;
TinyGPSPlus gps;
static void smartDelay(unsigned long ms);
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <TinyGPSPlus.h>
EspSoftwareSerial::UART gpsSerial;
TinyGPSPlus gps;
void displayInfo();
#include <Arduino.h>
#include <SoftwareSerial.h>
/*
lib_deps =
plerup/EspSoftwareSerial @ ^8.2.0
tinyu-zhao/TinyGPSPlus-ESP32 @ ^0.0.2
*/
EspSoftwareSerial::UART gpsSerial;
#include <Arduino.h>
#include <QMC5883LCompass.h>
/*
lib: mprograms/QMC5883LCompass @ ^1.2.3
*/