So, learning by doing

I have i beadboard with a ArduinoProMini on it. The Testcode is working for me:
Code: Select all
// Arduino MAVLink test code.
#include <FastSerial.h>
#include "../mavlink/include/mavlink.h" // Mavlink interface
FastSerialPort0(Serial);
void setup() {
Serial.begin(57600);
}
void loop() {
// Define the system type (see mavlink_types.h for list of possible types)
int system_type = MAV_QUADROTOR;
int autopilot_type = MAV_AUTOPILOT_GENERIC;
// Initialize the required buffers
mavlink_message_t msg;
uint8_t buf[MAVLINK_MAX_PACKET_LEN];
// Pack the message
// mavlink_message_heartbeat_pack(system id, component id, message container, system type, MAV_AUTOPILOT_GENERIC)
mavlink_msg_heartbeat_pack(123, 234, &msg, system_type, autopilot_type);
// Copy the message to send buffer
uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
// Send the message (.write sends as bytes)
Serial.write(buf, len);
comm_receive();
}
void comm_receive() {
mavlink_message_t msg;
mavlink_status_t status;
//receive data over serial
while(Serial.available() > 0) {
uint8_t c = Serial.read();
//try to get a new message
if(mavlink_parse_char(MAVLINK_COMM_0, c, &msg, &status)) {
// Handle message
switch(msg.msgid) {
case MAVLINK_MSG_ID_SET_MODE: {
// set mode
}
break;
case MAVLINK_MSG_ID_ACTION:
// EXECUTE ACTION
break;
default:
//Do nothing
break;
}
}
// And get the next one
}
delay(500);
}
, but when i add the lines
Code: Select all
//try to set some values
int xacc = 10;
int yacc = 11;
int zacc = 12;
int xgyro = 100;
int ygyro = 101;
int zgyro = 102;
int xmag = 200;
int ymag = 201;
int zmag = 202;
mavlink_msg_raw_imu_pack(100, 200, &msg, 0, xacc, yacc, zacc, xgyro, ygyro, zgyro, xmag, ymag, zmag);
uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
// Send the message (.write sends as bytes)
Serial.write(buf, len);
then the complete code looks like this:
Code: Select all
// Arduino MAVLink test code.
#include <FastSerial.h>
#include "../mavlink/include/mavlink.h" // Mavlink interface
FastSerialPort0(Serial);
void setup() {
Serial.begin(57600);
}
void loop() {
// Define the system type (see mavlink_types.h for list of possible types)
int system_type = MAV_QUADROTOR;
int autopilot_type = MAV_AUTOPILOT_GENERIC;
// Initialize the required buffers
mavlink_message_t msg;
uint8_t buf[MAVLINK_MAX_PACKET_LEN];
// Pack the message
// mavlink_message_heartbeat_pack(system id, component id, message container, system type, MAV_AUTOPILOT_GENERIC)
mavlink_msg_heartbeat_pack(123, 234, &msg, system_type, autopilot_type);
// Copy the message to send buffer
uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
// Send the message (.write sends as bytes)
Serial.write(buf, len);
//try to set some values
int xacc = 10;
int yacc = 11;
int zacc = 12;
int xgyro = 100;
int ygyro = 101;
int zgyro = 102;
int xmag = 200;
int ymag = 201;
int zmag = 202;
mavlink_msg_raw_imu_pack(100, 200, &msg, 0, xacc, yacc, zacc, xgyro, ygyro, zgyro, xmag, ymag, zmag);
uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);
// Send the message (.write sends as bytes)
Serial.write(buf, len);
comm_receive();
}
void comm_receive() {
mavlink_message_t msg;
mavlink_status_t status;
//receive data over serial
while(Serial.available() > 0) {
uint8_t c = Serial.read();
//try to get a new message
if(mavlink_parse_char(MAVLINK_COMM_0, c, &msg, &status)) {
// Handle message
switch(msg.msgid) {
case MAVLINK_MSG_ID_SET_MODE: {
// set mode
}
break;
case MAVLINK_MSG_ID_ACTION:
// EXECUTE ACTION
break;
default:
//Do nothing
break;
}
}
// And get the next one
}
delay(500);
}
i get the error:
Code: Select all
ArduinoMAVLink.cpp: In function 'void loop()':
ArduinoMAVLink:43: error: redeclaration of 'uint16_t len'
ArduinoMAVLink:25: error: 'uint16_t len' previously declared here
i am new to arduino and did all programming before with bascom, a basic like programming language

can someone explain me how to solve the mistake? i know that i declare the uint16_t len twice, but i dont know how to solve...