The complete instruction is published on Makezine.com
http://makezine.com/projects/build-a-ball-counting-robot-using-makeblock-and-lego/
Here is the program,
#include <Makeblock.h>
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
MeServo servoDriver(PORT_3,DEV1);
MeDCMotor motor1(M1);
MeDCMotor motor2(M2);
MeLimitSwitch limitSwitch(PORT_6);
MeNumericDisplay disp(PORT_5);
uint8_t pos1=90;
uint8_t pos2=0;
uint8_t motorspeed = 100;
uint8_t flag;
uint16_t num=0;
unsigned long time1;
unsigned long time2;
void setup()
{
servoDriver.begin();
servoDriver.write(pos1);
disp.display(num);
Serial.begin(9600);
}
void loop()
{
motor();
motor1.run(100);
motor2.run(motorspeed-82);
check();
}
void motor()
{
time1 = millis();
while(millis()-time1<700)
{
servoDriver.write(pos2);
check();
}
time2 = millis();
while(millis()-time2<3000)
{
servoDriver.write(pos1);
check();
}
}
void check()
{
if (!limitSwitch.touched())
{
motor2.stop();
motor1.stop();
servoDriver.write(pos1);
num+=1;
disp.display(num);
buzzerOn();
delay(300);
buzzerOff();
delay(1000);
while(!limitSwitch.touched());
motor2.run(motorspeed-82);
}
}