Ruslan_nig

ros_BlinkTestMy

Jun 18th, 2021
931
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <ros.h>
  3. #include <std_msgs/Int8.h>
  4.  
  5. ros::NodeHandle  nh;
  6.  
  7. void messageCb( const std_msgs::Int8& toggle_msg){
  8.   if (toggle_msg.data==4){
  9.   digitalWrite(LED_BUILTIN, HIGH-digitalRead(LED_BUILTIN));   // blink the led
  10.   }
  11. }
  12.  
  13. ros::Subscriber<std_msgs::Int8> sub("chatter", &messageCb );
  14.  
  15. void setup()
  16. {
  17.   pinMode(LED_BUILTIN, OUTPUT);
  18.   nh.initNode();
  19.   nh.subscribe(sub);
  20. }
  21.  
  22. void loop()
  23. {  
  24.   nh.spinOnce();
  25.   delay(500);
  26. }
RAW Paste Data