बम्पर स्विच#
परिचय#
बम्पर स्विच को कब दबाया और छोड़ा जाता है, इसका पता लगाने के लिए bumper क्लास का उपयोग किया जाता है।
क्लास कंस्ट्रक्टर#
bumper(
int32_t index );
क्लास डिस्ट्रक्टर#
bumper ऑब्जेक्ट को नष्ट करता है और उससे जुड़े संसाधनों को मुक्त करता है।
virtual ~bumper();
पैरामीटर#
पैरामीटर |
प्रकार |
विवरण |
|---|---|---|
|
|
स्मार्ट पोर्ट जिससे बम्पर स्विच जुड़ा हुआ है, उसे |
उदाहरण#
// Create a bumper instance in Port 1
bumper Bumper1 = bumper(PORT1);
सदस्य कार्य#
bumper क्लास में निम्नलिखित सदस्य फ़ंक्शन शामिल हैं:
pressing— यदि बम्पर स्विच दबाया जा रहा है तो रिटर्न करता है।pressed— बम्पर स्विच दबाए जाने पर कॉल किए जाने वाले फ़ंक्शन को पंजीकृत करता है।released— बम्पर स्विच रिलीज़ होने पर कॉल किए जाने वाले फ़ंक्शन को रजिस्टर करता है।
किसी भी bumper सदस्य फ़ंक्शन को कॉल करने से पहले, एक bumper इंस्टेंस बनाना आवश्यक है, जैसा कि नीचे दिखाया गया है:
/* This constructor is required when using VS Code.
Bumper Switch configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create a bumper instance in Port 1
bumper Bumper1 = bumper(PORT1);
pressing#
यदि बम्पर स्विच वर्तमान में दबा हुआ है तो यह वापस लौटता है।
Available Functionsint32_t pressing();
यह फ़ंक्शन कोई पैरामीटर स्वीकार नहीं करता है।
Return Valuesयह int32_t लौटाता है जो दर्शाता है कि बम्पर स्विच दबाया जा रहा है या नहीं।
1— बम्पर स्विच दबाया जा रहा है।0— बम्पर स्विच दबाया नहीं जा रहा है।
pressed#
बम्पर स्विच दबाए जाने पर कॉल किए जाने वाले फ़ंक्शन को पंजीकृत करता है।
Available Functionsvoid pressed( void (* callback)(void) );
पैरामीटर |
प्रकार |
विवरण |
|---|---|---|
|
|
एक फ़ंक्शन का पॉइंटर जिसे बम्पर दबाने पर कॉल किया जाएगा। फ़ंक्शन में कोई पैरामीटर नहीं होना चाहिए और उसे void रिटर्न करना चाहिए। |
इस कार्य पर कीमत के लिहाज से कुछ भी रिटर्न नहीं मिलता है।
Examplesकॉलबैक फ़ंक्शन को परिभाषित करें (
int main()के बाहर)// Display a message when bumper is pressed void BumperPressed() { Brain.Screen.print("Bumper pressed"); }
int main()के अंदर कॉलबैक को रजिस्टर करेंint main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Run BumperPressed when the value of the Bumper Switch is pressed. Bumper1.pressed(BumperPressed); }
released#
बम्पर स्विच को छोड़ने पर कॉल किए जाने वाले फ़ंक्शन को पंजीकृत करता है।
Available Functionsvoid released( void (* callback)(void) );
पैरामीटर |
प्रकार |
विवरण |
|---|---|---|
|
|
एक फ़ंक्शन का पॉइंटर जिसे बम्पर रिलीज़ होने पर कॉल किया जाएगा। फ़ंक्शन में कोई पैरामीटर नहीं होना चाहिए और उसे void रिटर्न करना चाहिए। |
इस कार्य पर कीमत के लिहाज से कुछ भी रिटर्न नहीं मिलता है।
Examplesकॉलबैक फ़ंक्शन को परिभाषित करें (
int main()के बाहर)// Display a message when bumper is released void BumperReleased() { Brain.Screen.print("Bumper released"); }
int main()के अंदर कॉलबैक को रजिस्टर करेंint main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Run BumperReleased when the value of the Bumper Switch is released. Bumper1.released(BumperReleased); }