How to really blink an LED on an arduino through ROS
I set up ROS with an arduino and successfully implemented the blink-example. However, I would like to really make it blink, e.g. to turn the LED on and off with a high frequency. Unfortunately, I have not managed to do that. The code I tried is:
#include <ros.h>
#include <std_msgs/Empty.h>
ros::NodeHandle nh;
void messageCb( const std_msgs::Empty& toggle_msg){
digitalWrite(13, HIGH-digitalRead(13));
delay(100);
digitalWrite(13, LOW-digitalRead(13));
delay(100); // blink the led
}
ros::Subscriber<std_msgs::Empty> sub("toggle_led", &messageCb );
void setup()
{
pinMode(13, OUTPUT);
nh.initNode();
nh.subscribe(sub);
}
void loop()
{
nh.spinOnce();
}
As can be seen, I tried to give the command to be executed in the message as if the message contains the actions to be carried out, but it did not work so I was wondering what the proper way to do sequences of action with one message would be?
Thank you.