Microduino
  • Início Rápido
  • Introdução ao Software
    • Baixe e instale
    • Interface do software
    • Palco e Personagens
    • Modos de Execução
    • Funções Básicas do mDesigner
    • Atualizações do mDesigner
    • Blocos
    • Abas de Blocos
  • IdeaBit
    • Software
    • Sensores e Atuadores
      • Led RGB
      • Matriz de led
      • Buzzer
      • Botão
      • Sensor de ruído (MIC)
      • Acelerômetro
      • Sensor touch
      • Sensor de luminosidade
    • Especificações Técnicas Adicionais
  • Kit mCookie
    • mCenter+
    • Matriz de LED 8x8
    • Sensor Crash
    • Led RGB
    • Potenciômetro
    • Sensor de Luminosidade
    • Sensor Infravermelho
    • Sensor Touch
    • Sensor Buzzer
    • Sensor Motion
    • Sensor de Refletância
    • Módulo Motor DC
    • mCookie - OLED
    • Sensor Gesture
    • Matriz de LED 5x5
  • Itty Bitty Buggy
    • IBB
    • Modos de Funcionamento
  • Ideabord
    • Manual de Uso
    • Sensores e Atuadores
    • Jogos
  • Microduino
    • Configurando a IDE do Arduino
    • Módulos
    • Sensores
    • Conectando no Cayenne
  • mRobots
    • App mRobots
    • Testando conexão (BLE+mRobots)
  • FAQ
    • FAQ
Powered by GitBook
On this page

Was this helpful?

  1. mRobots

Testando conexão (BLE+mRobots)

Projeto exemplo, vamos testar a conexão do nosso projeto com o app mRobots fazendo com que um LED acenda caso nosso acelerador (canal 4) saia da posição 0 (zero).

Hardware necessário:

  • mBattery

  • mCookie Core+

  • mCookie Hub

  • LED colorido (qualquer cor)

Becoming a super hero is a fairly straight forward process:

$ give me super-powers

Super-powers are granted randomly so please submit an issue if you're not happy with yours.

Once you're strong enough, save the world:

#include <Microduino_Protocol.h>
#include <Microduino_Motor.h>

#define _DEBUG  //DEBUG调试

#define BLE_SPEED 57600  //velocidade transmissão da porta
#define CHANNEL_NUM   8  //número de canais 
#define SAFE_TIME_OUT 250   //timeout de segurança
#define MAX_THROTTLE 255 //valor output acelerador < 255
#define MAX_STEERING 512 //valor máximo direção  < 512
#define CHANNEL_THROTTLE  1 //definir canal do acelerador
#define CHANNEL_STEERING  0 //definir canal da direção

Motor MotorLeft(MOTOR0_PINA, MOTOR0_PINB);
Motor MotorRight(MOTOR1_PINA, MOTOR1_PINB);

#define ProSerial Serial
ProtocolSer bleProtocol(&ProSerial, 16);  //utiliza ProSerial,protocol de 16 bytes

///////////////////////////////////////////////////////////
uint16_t channalData[CHANNEL_NUM]; //8 canais (ver define linha 7)
int16_t throttle = 0; //acelerador
int16_t steering = 0; //direção
unsigned long safe_ms = millis();

uint8_t recCmd;

void setup() {

  bleProtocol.begin(BLE_SPEED);
  pinMode(D6,OUTPUT);
  MotorLeft.begin();   //valor inicial motor esquerdo
  MotorRight.begin();  //valor inicial motor direito
}

void loop() {
  if (bleProtocol.available())
  {
    bleProtocol.readWords(&recCmd, channalData, 8);

    throttle = map(channalData[CHANNEL_THROTTLE], 1000, 2000, -MAX_THROTTLE, MAX_THROTTLE);
    steering = map(channalData[CHANNEL_STEERING], 1000, 2000, -MAX_STEERING, MAX_STEERING);

    MotorLeft.setSpeed((throttle + steering / 2));
    MotorRight.setSpeed(-(throttle - steering / 2));

#ifdef _DEBUG
    Serial.print("DATA OK :[");
    for (int a = 0; a < CHANNEL_NUM; a++) {
      Serial.print(channalData[a]);
      Serial.print(" ");
    }
    Serial.print("],throttle:");
    Serial.print(throttle);  //+153
    Serial.print(",steering:");
    Serial.println(steering);
    if(abs(throttle)>128)
    {
      digitalWrite(D6,HIGH);
    }else
    {
      digitalWrite(D6,LOW);
    }
#endif
    safe_ms = millis();
  }

  if (safe_ms > millis()) safe_ms = millis();
  if (millis() - safe_ms > SAFE_TIME_OUT) {
    MotorLeft.setSpeed(FREE);  //definir a posição do motor esquerdo como livre,ou seja velocidade=0
    MotorRight.setSpeed(FREE); //definir a posição do motor direito como livre,ou seja velocidade=0
  }
}

PreviousApp mRobotsNextFAQ

Last updated 3 years ago

Was this helpful?