Last active
July 23, 2024 19:43
-
-
Save umhan35/f7dfd3ae935af0c849e1338a62c2f3e6 to your computer and use it in GitHub Desktop.
This file contains 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 <ros.h> | |
#include <std_msgs/String.h> | |
#include <std_srvs/Empty.h> | |
ros::NodeHandle nh; | |
bool messageCb(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res) { | |
digitalWrite(LED_BUILTIN, HIGH-digitalRead(LED_BUILTIN)); // blink the led | |
nh.loginfo("LED is ON"); | |
return true; | |
} | |
ros::ServiceServer<std_srvs::Empty::Request, std_srvs::Empty::Response> blinkServer("/led/blink", &messageCb); | |
void setup() | |
{ | |
pinMode(LED_BUILTIN, OUTPUT); | |
nh.initNode(); | |
nh.advertiseService(blinkServer); | |
} | |
void loop() | |
{ | |
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) | |
delay(10); // wait for a second | |
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW | |
delay(10); // wait for a second | |
nh.spinOnce(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment