Skip to content

Instantly share code, notes, and snippets.

@maxpromer
Created November 10, 2025 09:15
Show Gist options
  • Select an option

  • Save maxpromer/938912b4f11f7f618331e1559a24a76a to your computer and use it in GitHub Desktop.

Select an option

Save maxpromer/938912b4f11f7f618331e1559a24a76a to your computer and use it in GitHub Desktop.
#include <TinkerC6.h> // เรียกใช้ไลบรารี่ Tinker C6
void setup() {
Serial.begin(115200); // เริ่มใช้งาน Serial Monitor
TinkerC6.Power.enable12V(); // สั่งเปิดใช้ไฟเลี้ยง 12V
}
void loop() {
float mA = TinkerC6.Analog.getCurrent() + 0.08; // อ่านค่าช่อง 4-20mA เก็บลงตัวแปร mA
float percent = (mA - 4.0) * 100.0 / (20.0 - 4.0);
if (percent < 0) percent = 0;
if (percent > 100) percent = 100;
Serial.printf("Analog is %.02f mA, Percent is %.01f\n", mA, percent); // แสดงผลค่าใน Serial Monitor
delay(1000); // หน่วงเวลา 1 วินาที
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment