Help for servo question

Hi, sorry for my terrible english but I'm italian. I'm a student and i love Arduino :slight_smile:
I would like to make this project but Messenger.h don't work. i would like to use CmdMessenger but i'm very confused. Any help please?

the link of the project:
http://sprae.jogger.pl/2012/01/13/licznik-do-live-for-speed-z-arduino-cz-2-predkosciomierz/

the code:

#include <Messenger.h>
#include <Servo.h>

#define SPEED_SERVO_PIN 2
#define SPEED_SERVO_0_US 2800
#define SPEED_SERVO_200_US 870

Servo hand;
Messenger message;

void sendVersion()
{
  Serial.println(F("AD 01.12 ArduDash"));
}

void sendOK()
{
  Serial.println(F("OK"));
}

void sendERROR()
{
  Serial.println(F("ERROR"));
}

void setSpeedServo(int speed)
{
  int microseconds = map(speed, 0, 200, SPEED_SERVO_0_US, SPEED_SERVO_200_US);
  hand.writeMicroseconds(microseconds);
}

void setSpeed()
{
  int speed = message.readInt();
  if (speed < 0 || speed > 230)
  {
    sendERROR();
    return;
  }
  setSpeedServo(speed);
  sendOK();
}

void onMessage()
{
  switch (message.readChar())
  {
    case 'V':
      sendVersion();
      break;
    case 'S':
      setSpeed();
      break;
    default:
      sendERROR();
      break;
  }
}

void serialEvent()
{
  message.process(Serial.read());
}

void setup()
{
  hand.attach(2);
  Serial.begin(19200);
  message.attach(onMessage);
  
  setSpeedServo(0);
}

void loop()
{
}

In any language, "but Messenger.h don't work" is pretty lame. You need to be much more specific. Is it causing a compile problem? Or, is it not working at run time?

It's a compile problem infact I would like to use CmdMessenger. But I'm not able...
http://sprae.jogger.pl/2012/01/02/licznik-do-live-for-speed-z-arduino-cz-1/ Python program work very well... speed is very precise.

But I'm not able

Why not? What is stopping you? Show the error messages.

#include <CmdMessenger.h>
#include <Servo.h>

#define SPEED_SERVO_PIN 2
#define SPEED_SERVO_0_US 2800
#define SPEED_SERVO_200_US 870

Servo hand;
Messenger message;

"'Messenger' does not a name type"

"'Messenger' does not a name type"

Is that a surprise? You are including CmdMessenger.h, which defines a class called CmdMessenger, and then trying to create an instance of some undefined class called Messenger.

You might want to create an instance of CmdMessenger, instead. Just a thought.

CmdMessenger message???

CmdMessenger message???

Yes... Unless you want

CmdMessenger someThingElse;;;

or maybe

CmdMessenger joe;;;

excuse me, I still do not understand

excuse me, I still do not understand

Just read the first word of my last reply, then.

#include <Servo.h>

#define SPEED_SERVO_PIN 2
#define SPEED_SERVO_0_US 2800
#define SPEED_SERVO_200_US 870

Servo hand;
CmdMessenger

void sendVersion()

expected constructor destructor or type conversion before ‘void’ :blush: excuse me =(

CmdMessenger

You need an instance of this class.
This just names the class, not the instance.

I think I will leave this project. I'm not able

See reply #7

I'm sorry, please could change everything code for me? i'm only 14 years old...

I think that asking a lot. I just want to do something other than simple LEDs and a potentiometer/servo code. Excuse me.

Change

Messenger message;

To this

CmdMessenger message;

They are telling you it's called CmdMessenger not just Messenger..

So, there is a list of candidate constructors.
Pick the one that matches your requirements.

I had a look at this and I must say, it baffles me (which is easily done). For one the example code that website gives is full of errors. I have attempted to fix the errors but was unsuccessful on some of them (trust me, there was a ton).

This is the code that I came up with:

#include <Messenger.h>
#include <Servo.h>

#Define SPEED_SERVO_PIN = 2
#Define SPEED_SERVO_0_US = 2800
#Define SPEED_SERVO_200_US = 870

Servo hand;
 Messenger message;

 sendVersion void()
 {
 Serial.Println(F ("AD ArduDash 01.12"));
 }

 Sendok void()
 {
 Serial.Println(F ("OK"));
 }

 sendError void()
 {
 Serial.Println(F ("ERROR"));
 }

 setSpeedServo void(int speed)
 {
 int microseconds = map (speed, 0, 200, SPEED_SERVO_0_US, SPEED_SERVO_200_US);
 hand.writeMicroseconds (microseconds);
 }

 setSpeed void()
 {
 int speed = message.readInt ();
 if (speed <0 | | speed> 230)
 {
 sendError();
 return;
 }
 setSpeedServo(speed);
 Sendok();
 }

 void OnMessage()
 {
 switch(message.readChar())
 {
 case 'V':
 sendVersion();
 break;
 case 'S':
 setSpeed();
 break;
 default:
 sendError();
 break;
 }
 }

 serialEvent void()
 {
 message.process(Serial.read());
 }

 void setup()
 {
 hand.attach (2);
 Serial.Begin (19200);
 message.attach(OnMessage);

 setSpeedServo(0);
 }

 void loop ()
 {
 }

It is "Messenger" according to the library and the example code.

Messenger message;

But can't get it to compile myself. If someone that has more knowledge on libraries could look at it, they could tell you more.

Here's the compile errors:

sketch_oct31a.ino:4:2: error: invalid preprocessing directive #Define
sketch_oct31a.ino:5:2: error: invalid preprocessing directive #Define
sketch_oct31a.ino:6:2: error: invalid preprocessing directive #Define
sketch_oct31a:9: error: expected constructor, destructor, or type conversion before 'void'
sketch_oct31a:10: error: expected constructor, destructor, or type conversion before 'void'
sketch_oct31a:11: error: expected constructor, destructor, or type conversion before 'void'
sketch_oct31a:12: error: expected constructor, destructor, or type conversion before 'void'
sketch_oct31a:13: error: expected constructor, destructor, or type conversion before 'void'
sketch_oct31a:15: error: expected constructor, destructor, or type conversion before 'void'
sketch_oct31a:2: error: 'Messenger' does not name a type
sketch_oct31a:4: error: expected constructor, destructor, or type conversion before 'void'

First, it's #define, not #Define. That will get rid of the 1st three error messages.

Second, you have the function name in front of the type. That's completely backwards. There goes the next 6 messages.

Third, Messenger is obsolete. CmdMessenger replaces it. Trying to modify examples for obsolete classes is a waste of time. Doing so when you don't know what you are doing is even more so.