Mowayduino robot API and IDE testing script

Script to test the Mowayduino robot API:

 

//****************************************
//  Libraries
//****************************************
#include "MowayduinoRobot.h"
#include 
#include 

//****************************************
//  Objects
//****************************************
mowayduinorobot robot;

//****************************************
//  RF event function (necessary for compiling)
//****************************************
void RfDataReady();
void RfDataReady()
{}


//****************************************
//
//  Main Program
//
//****************************************
void setup()
{
  robot.beginMowayduino();
  Serial.begin(57600);
  delay(2000);
}

void loop()
{
  robot.readObstacle();
  if(robot.Obstacle[IR_CL] > 512 || robot.Obstacle[IR_CR] > 512)
  {
    // There is a front obstacle
    
    if(robot.Obstacle[IR_LL] > 512 && robot.Obstacle[IR_LR] > 512)
    {
      // Both sides also blocked
      robot.RotateLeft(100, 180);
      LedsRotate();
    } else {
      if(robot.Obstacle[IR_LL] <= 512) 
      {
        robot.RotateLeft(100, 90);
        LedsRotate();
      } else {
        robot.RotateRight(100, 90);
        LedsRotate();
      }
    }
  } else {
    LedsStraight();
    robot.Straight(100);
  }
    delay(100);
}

//****************************************
//
//  Functions
//
//****************************************
void LedsStraight()
{
  robot.Fronton();
  robot.Greenon();  
  robot.Brakeoff();
  robot.Redoff();  
}

void LedsRotate()
{
  robot.Frontoff();
  robot.Greenoff();  
  robot.Brakeon();
  robot.Redon();  
}

 

Mowayduino

Mowayduino

Posted in Arduino, C/C++, DIY, Electronics, Programming, Robots Tagged with: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*