I tried to change it myself, but it did not work. I took a look into the Makeblock.cpp file too and think I found the answer to why we don’t have to tell witch port to use. The Gyro uses the Wire library and I guess it will make a search for any modules when we write gyro.begin().
Then why does the example code not work (no output on serial monitor)? I tracked it to the call for Serial.available(). When I remove the if statement, and just use a delay(100) between gyro.update() I get readings on my serial monitor.
I searched for the answer in SoftwareSerial resources and found this:
You can’t write code like this:
void loop()
{
device1.listen();
if (device1.available() > 0)
{
int c = device1.read();
...
}
device2.listen();
if (device2.available() > 0)
{
int c = device2.read();
...
}
}
This code will never do anything but activate one device after the other.
The example code does not call any other device than Serial, so I don’t know why the problem occur, but I can see that something like this is what happens.
So this edited example code will work:
#include "Makeblock.h"
#include <Wire.h>
#include <SoftwareSerial.h>
MeGyro gyro;
void setup(){
gyro.begin();
}
void loop(){
gyro.update();
Serial.read();
Serial.print("X:");
Serial.print(gyro.angleX());
Serial.print(" Y:");
Serial.print(gyro.angleY());
Serial.print(" Z:");
Serial.println(gyro.angleZ());
delay(100);
}