MassimilianoMichele Valentini
Published © Apache-2.0

Tutorial – How to control motor with The Tactigon – Part II

In this article we’re going to learn how to connect The Tactigon to a motor control board and communicate with it. Part II - Sketch

BeginnerProtip2 hours188
Tutorial – How to control motor with The Tactigon – Part II

Things used in this project

Hardware components

The Tactigon One
The Tactigon One
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

CINGO.ino

Arduino
#include <tactigon_led.h>
#include <tactigon_BLE.h>
#include <tactigon_UserSerial.h>


//RGB LEDs
T_Led rLed, bLed, gLed;

//BLE Manager, BLE Characteristic and its UUID
T_BLE bleManager;
T_BLE_Characteristic cmdChar;
UUID uuid;

//UART 
T_UserSerial tSerial;

//Used for LEDs cycle
int  ticksLed, stp;

/*----------------------------------------------------------------------*/
void cbBLEcharWritten(uint8_t *pData, uint8_t dataLen)
{
  //Sends received data to uart
  tSerial.write((char*)pData, dataLen);
  //Blinks LEDs, turned off by next state in loop()
  rLed.on();
  gLed.on();
  bLed.on();
}

/*----------------------------------------------------------------------*/
void cbUartRxByte(uint8_t bb){
  
}

/*----------------------------------------------------------------------*/
void cbUartRxLine(uint8_t *pLine, uint8_t len){

}

/*----------------------------------------------------------------------*/
void setup() {

  char charProg;

  ticksLed = 0;
  stp = 0;

  rLed.init(T_Led::RED);
  gLed.init(T_Led::GREEN);
  bLed.init(T_Led::BLUE);

  rLed.off();
  gLed.off();
  bLed.off();

  //init role
  bleManager.InitRole(TACTIGON_BLE_PERIPHERAL);

  uuid.set("c1c0760d-503d-4920-b000-101e7306b001");   //command char
  cmdChar = bleManager.addNewChar(uuid, 18, 1);
  charProg = cmdChar.setWcb(cbBLEcharWritten);

  //init user serial
  tSerial.init(T_UserSerial::B_9600);
  tSerial.setRxByteCB(cbUartRxByte);
  tSerial.setRxLineCB(cbUartRxLine);

}

/*----------------------------------------------------------------------*/
void loop() {
  
  //Cycle rgb leds
  if (GetCurrentMilli() >= (ticksLed + (1000 / 1)))
  {
    char buff[4];
    int i;

    ticksLed = GetCurrentMilli();

    if (stp == 0)
    {
      rLed.on();
      gLed.off();
      bLed.off();
    }
    else if (stp == 1)
    {
      rLed.off();
      gLed.on();
      bLed.off();
    }
    else if (stp == 2)
    {
      rLed.off();
      gLed.off();
      bLed.on();
    }

    stp = (stp + 1) % 3;
  }

}

Credits

Massimiliano

Massimiliano

28 projects • 96 followers
I'm an engineer and I like robotics, embedded systems and linux. I spent a lot of time in automation and firmware development.
Michele Valentini

Michele Valentini

20 projects • 48 followers
From Pepper growing to CNC milling, i don't like to waste time sleeping

Comments