Integration of Ambient Light sensor VEML7700 with Nucleo board. ROS Enabled

Dependencies:   mbed VEML7700

Committer:
zillkhan
Date:
Fri Sep 10 09:24:48 2021 +0000
Revision:
1:ca82df4237eb
Parent:
0:d94848220e71
Child:
2:1d1f6cd9d8b1
Test Code for SharpIR GP2Y0A51SK0F

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Tomas 0:d94848220e71 1 #include "mbed.h"
zillkhan 1:ca82df4237eb 2 #include <ros.h>
zillkhan 1:ca82df4237eb 3 #include <std_msgs/Float32.h>
zillkhan 1:ca82df4237eb 4 #include <std_msgs/String.h>
Tomas 0:d94848220e71 5 #include "SHARPIR.h"
Tomas 0:d94848220e71 6
zillkhan 1:ca82df4237eb 7
zillkhan 1:ca82df4237eb 8 ros::NodeHandle nh;
zillkhan 1:ca82df4237eb 9
zillkhan 1:ca82df4237eb 10 std_msgs::Float32 data;
zillkhan 1:ca82df4237eb 11 ros::Publisher sharpir("sharpir", &data);
zillkhan 1:ca82df4237eb 12
zillkhan 1:ca82df4237eb 13 SHARPIR Sensor(A0);
zillkhan 1:ca82df4237eb 14
zillkhan 1:ca82df4237eb 15
Tomas 0:d94848220e71 16 int main() {
Tomas 0:d94848220e71 17 float DistanceCM;
zillkhan 1:ca82df4237eb 18
zillkhan 1:ca82df4237eb 19 nh.initNode();
zillkhan 1:ca82df4237eb 20 nh.advertise(sharpir);
zillkhan 1:ca82df4237eb 21
Tomas 0:d94848220e71 22 while (1) { //creates an eternal loop
zillkhan 1:ca82df4237eb 23
zillkhan 1:ca82df4237eb 24 DistanceCM=Sensor.cm();
zillkhan 1:ca82df4237eb 25 //sprintf (buffer, "%f", DistanceCM);
zillkhan 1:ca82df4237eb 26
zillkhan 1:ca82df4237eb 27 data.data = DistanceCM;
zillkhan 1:ca82df4237eb 28 sharpir.publish( &data );
zillkhan 1:ca82df4237eb 29
zillkhan 1:ca82df4237eb 30 nh.spinOnce();
zillkhan 1:ca82df4237eb 31 wait_ms(1000);
Tomas 0:d94848220e71 32 }
Tomas 0:d94848220e71 33 }