my hardware is working but on doing rostopic echo reading is 0.0
Code below:
/*
rosserial PubSub Example
Prints "hello world!" and toggles led
*/
#include <ros.h>
#include <std_msgs/Float32.h>
#include <std_msgs/Int32.h>
#include <Servo.h>
#include <dht11.h>
#define DHT11PIN 4
int pos = 0 ;
dht11 DHT11;
ros::NodeHandle nh;
Servo myservo;
void messageCb( const std_msgs::Int32& movewiper) {
if (movewiper.data == 1) {
myservo.write(180);
}
else {
myservo.write(0);
delay(15);
}
}
ros::Subscriber<std_msgs::Int32> sub("Servo", messageCb );
std_msgs::Float32 humidity_range;
ros::Publisher humidity("humidity", &humidity_range);
//char hello[13] = "hello world!";
void setup()
{
myservo.attach(9); //tell the arduino where the motor is attached and to control it
nh.initNode(); //for initializing
nh.advertise(humidity);
nh.subscribe(sub);
}
void loop()
{
int chk = DHT11.read(DHT11PIN);
if (DHT11.humidity > 60) {
for (pos = 0; pos <= 180; pos += 1) {
myservo.write(pos);
delay(15);
}
}
else {
myservo.write(0);
delay(15);
}
humidity.publish( &humidity_range );
nh.spinOnce();
delay(500);
}
Please properly format code snippets using the
101010
button.