Mercury altimeter के बोर्ड पर दो push buttons हैं। एक Mercury के लिए reset button है जिसे POWER कहा जाता है, और दूसरा boot button है जिसे BUTTON कहा जाता है।
आप अपने कोड में BUTTON का उपयोग एक सामान्य push button के रूप में आवश्यकतानुसार कर सकते हैं, हालांकि power button बोर्ड को रीबूट करेगा।
हम reset button का उपयोग यह याद रखने के लिए करते हैं कि यह पिछली रन में on या off था ताकि यह on/off switch के रूप में कार्य कर सके। अगर डिवाइस पिछली रन में off था तो अब यह चलेगा और on हो जाएगा। अगर डिवाइस पिछली रन में on था तो यह deep sleep mode में जाएगा।
निम्नलिखित कोड दिखाता है कि आप सामान्य button का उपयोग कैसे कर सकते हैं और जब आप इसे दबाते हैं तो Serial में प्रिंट कर सकते हैं।
/* * Mercury V1 (ESP32-C6) Button example * जब आप button दबाते हैं तो Serial में प्रिंट करता है।
* डिवाइस को upload करने के बाद serial monitor को कनेक्ट करें। */ #include "Mercury_Pins.h" void setup() { pinMode(BUTTON, INPUT_PULLUP); // आपको BUTTON input को pullup करना होगा, यह दबाया न जाने पर 1 होगा और दबाए जाने पर 0 होगा। Serial.begin(115200); delay(1000); Serial.println("Button की प्रतीक्षा में..."); } void loop() { if(digitalRead(BUTTON) == 0){ // अगर BUTTON pin = 0 है तो button दबाया गया है। Serial.println("Button दबाया गया।"); } delay(500); }#pragma once /* * Mercury (ESP32-C6) Pin Definitions * Board-specific GPIO assignments */ // ── Status LED (NeoPixel) ── #define LEDPOWER 3 // NeoPixel power (drive HIGH to enable) #define LED 2 // NeoPixel data signal // ── I2C Bus ── #define SDA 21 // I2C data #define SCL 22 // I2C clock // ── Sensor Power ── #define VACC 20 // Sensor power rail (drive HIGH to enable) // ── General Purpose Ports ── #define GP06 6 // GP06 port #define GP07 7 // GP07 port // ── High Current Output ── #define OUT1 5 // High current output (e.g. pyro / relay) // ── Battery Bar LEDs ── #define BL1 4 // Battery LED 1 (lowest) #define BL2 14 // Battery LED 2 #define BL3 15 // Battery LED 3 #define BL4 18 // Battery LED 4 #define BL5 19 // Battery LED 5 (highest) // ── Indicators ── #define DISK 8 // Disk activity LED // ── Analogue / Detection ── #define BATIN 0 // Battery voltage (1:1 divider) #define USBDETECT 1 // USB power detect (HIGH = USB present) #define BUTTON 9 // BUTTON on the board, boot button but can be used