Trata-se de um primeiro protótipo para explorar recursos gerais do Arduino relacionados à robotica. O tema é de grande interesse para a área de ensino, uma vez que desperta nos alunos a vontade de buscar os conhecimentos complementares necessários relacionados à Física, Matemática, Eletricidade, Mecânica, dentre outros, a fim de resolver os desafios que surgem.
Este protótipo é simples, com dois motores para movimento das rodas, um Arduino Mega, um módulo bluetooth para comunicação com Smartphones, além de alguns mecanismos mecanicos, uma caixa adaptada de porta sacos de lixo, um módulo para controle de motores.
Figura 1 - Projeto Joaninha
Figura 2 - Projeto Joaninha com proteção
Figura 3 - Projeto Joaninha - detalhe da frente - sensor e display
********************************************************************
Fonte do Programa
Autor: Arnott Ramos Caiado
bibliotecas e informações de base obtidas em
www.filipeflop.com.br
********************************************************************
#include <LedControl.h>
#include <AFMotor.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//Carrega a biblioteca do sensor ultrassonico
#include <Ultrasonic.h>
#include <Servo.h>
//Define os pinos para o trigger e echo
#define pino_trigger 22
#define pino_echo 24
//Inicializa o sensor nos pinos definidos acima
Ultrasonic ultrasonic(pino_trigger, pino_echo);
const int buzzer = 26;
#define DIST_MINIMA 15
const int RECV_PIN = 15;
const int TKD2 = 2;
// Define o motor1 ligado a conexao 1
AF_DCMotor motor1(1);
// Define o motor2 ligado a conexao 2
AF_DCMotor motor2(2);
int CS =16;
// alfabeto com simbolos
const byte IMAGES[][8] = {
{
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000
},{
B00000000,
B00111110,
B01000001,
B01010101,
B01000001,
B01010101,
B01001001,
B00111110
},{
B00000000,
B00111110,
B01111111,
B01101011,
B01111111,
B01101011,
B01110111,
B00111110
},{
B00000000,
B00100010,
B01110111,
B01111111,
B01111111,
B00111110,
B00011100,
B00001000
},{
B00000000,
B00001000,
B00011100,
B00111110,
B01111111,
B00111110,
B00011100,
B00001000
},{
B00000000,
B00001000,
B00011100,
B00101010,
B01111111,
B00101010,
B00001000,
B00011100
},{
B00000000,
B00001000,
B00011100,
B00111110,
B01111111,
B00111110,
B00001000,
B00011100
},{
B00000000,
B00000000,
B00011100,
B00111110,
B00111110,
B00111110,
B00011100,
B00000000
},{
B11111111,
B11111111,
B11100011,
B11000001,
B11000001,
B11000001,
B11100011,
B11111111
},{
B00000000,
B00000000,
B00011100,
B00100010,
B00100010,
B00100010,
B00011100,
B00000000
},{
B11111111,
B11111111,
B11100011,
B11011101,
B11011101,
B11011101,
B11100011,
B11111111
},{
B00000000,
B00001111,
B00000011,
B00000101,
B00111001,
B01001000,
B01001000,
B00110000
},{
B00000000,
B00001000,
B00111110,
B00001000,
B00011100,
B00100010,
B00100010,
B00011100
},{
B00000000,
B00011000,
B00010100,
B00010000,
B00010000,
B00110000,
B01110000,
B01100000
},{
B00000000,
B00001111,
B00011001,
B00010001,
B00010011,
B00110111,
B01110110,
B01100000
},{
B00000000,
B00001000,
B00101010,
B00011100,
B01110111,
B00011100,
B00101010,
B00001000
},{
B00000000,
B01100000,
B01111000,
B01111110,
B01111111,
B01111110,
B01111000,
B01100000
},{
B00000000,
B00000011,
B00001111,
B00111111,
B01111111,
B00111111,
B00001111,
B00000011
},{
B00000000,
B00001000,
B00011100,
B00101010,
B00001000,
B00101010,
B00011100,
B00001000
},{
B00000000,
B01100110,
B01100110,
B01100110,
B01100110,
B00000000,
B01100110,
B01100110
},{
B00000000,
B00111111,
B01100101,
B01100101,
B00111101,
B00000101,
B00000101,
B00000101
},{
B00000000,
B00001100,
B00110010,
B01001000,
B00100100,
B00010010,
B01001100,
B00110000
},{
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B01111111,
B01111111,
B01111111
},{
B00000000,
B00001000,
B00011100,
B00101010,
B00001000,
B00101010,
B00011100,
B00111110
},{
B00000000,
B00001000,
B00011100,
B00111110,
B01111111,
B00011100,
B00011100,
B00011100
},{
B00000000,
B00011100,
B00011100,
B00011100,
B01111111,
B00111110,
B00011100,
B00001000
},{
B00000000,
B00001000,
B00001100,
B01111110,
B01111111,
B01111110,
B00001100,
B00001000
},{
B00000000,
B00001000,
B00011000,
B00111111,
B01111111,
B00111111,
B00011000,
B00001000
},{
B00000000,
B00000000,
B00000000,
B01110000,
B01110000,
B01110000,
B01111111,
B01111111
},{
B00000000,
B00000000,
B00010100,
B00100010,
B01111111,
B00100010,
B00010100,
B00000000
},{
B00000000,
B00001000,
B00011100,
B00011100,
B00111110,
B00111110,
B01111111,
B01111111
},{
B00000000,
B01111111,
B01111111,
B00111110,
B00111110,
B00011100,
B00011100,
B00001000
},{
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000
},{
B00000000,
B00011000,
B00111100,
B00111100,
B00011000,
B00011000,
B00000000,
B00011000
},{
B00000000,
B00110110,
B00110110,
B00010100,
B00000000,
B00000000,
B00000000,
B00000000
},{
B00000000,
B00110110,
B00110110,
B01111111,
B00110110,
B01111111,
B00110110,
B00110110
},{
B00000000,
B00001000,
B00011110,
B00100000,
B00011100,
B00000010,
B00111100,
B00001000
},{
B00000000,
B01100000,
B01100110,
B00001100,
B00011000,
B00110000,
B01100110,
B00000110
},{
B00000000,
B00111100,
B01100110,
B00111100,
B00101000,
B01100101,
B01100110,
B00111111
},{
B00000000,
B00011000,
B00011000,
B00011000,
B00110000,
B00000000,
B00000000,
B00000000
},{
B00000000,
B01100000,
B00110000,
B00011000,
B00011000,
B00011000,
B00110000,
B01100000
},{
B00000000,
B00000110,
B00001100,
B00011000,
B00011000,
B00011000,
B00001100,
B00000110
},{
B00000000,
B00000000,
B00110110,
B00011100,
B01111111,
B00011100,
B00110110,
B00000000
},{
B00000000,
B00000000,
B00001000,
B00001000,
B00111110,
B00001000,
B00001000,
B00000000
},{
B00000000,
B00000000,
B00000000,
B00000000,
B00110000,
B00110000,
B00110000,
B01100000
},{
B00000000,
B00000000,
B00000000,
B00000000,
B00111100,
B00000000,
B00000000,
B00000000
},{
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B01100000,
B01100000
},{
B00000000,
B00000000,
B00000110,
B00001100,
B00011000,
B00110000,
B01100000,
B00000000
},{
B00000000,
B00111100,
B01100110,
B01101110,
B01110110,
B01100110,
B01100110,
B00111100
},{
B00000000,
B00011000,
B00011000,
B00111000,
B00011000,
B00011000,
B00011000,
B01111110
},{
B00000000,
B00111100,
B01100110,
B00000110,
B00001100,
B00110000,
B01100000,
B01111110
},{
B00000000,
B00111100,
B01100110,
B00000110,
B00011100,
B00000110,
B01100110,
B00111100
},{
B00000000,
B00001100,
B00011100,
B00101100,
B01001100,
B01111110,
B00001100,
B00001100
},{
B00000000,
B01111110,
B01100000,
B01111100,
B00000110,
B00000110,
B01100110,
B00111100
},{
B00000000,
B00111100,
B01100110,
B01100000,
B01111100,
B01100110,
B01100110,
B00111100
},{
B00000000,
B01111110,
B01100110,
B00001100,
B00001100,
B00011000,
B00011000,
B00011000
},{
B00000000,
B00111100,
B01100110,
B01100110,
B00111100,
B01100110,
B01100110,
B00111100
},{
B00000000,
B00111100,
B01100110,
B01100110,
B00111110,
B00000110,
B01100110,
B00111100
},{
B00000000,
B00000000,
B00011000,
B00011000,
B00000000,
B00011000,
B00011000,
B00000000
},{
B00000000,
B00000000,
B00011000,
B00011000,
B00000000,
B00011000,
B00011000,
B00110000
},{
B00000000,
B00000110,
B00001100,
B00011000,
B00110000,
B00011000,
B00001100,
B00000110
},{
B00000000,
B00000000,
B00000000,
B00111100,
B00000000,
B00111100,
B00000000,
B00000000
},{
B00000000,
B01100000,
B00110000,
B00011000,
B00001100,
B00011000,
B00110000,
B01100000
},{
B00000000,
B00111100,
B01100110,
B00000110,
B00011100,
B00011000,
B00000000,
B00011000
},{
B00000000,
B00111000,
B01000100,
B01011100,
B01011000,
B01000010,
B00111100,
B00000000
},{
B00000000,
B00111100,
B01100110,
B01100110,
B01111110,
B01100110,
B01100110,
B01100110
},{
B00000000,
B01111100,
B01100110,
B01100110,
B01111100,
B01100110,
B01100110,
B01111100
},{
B00000000,
B00111100,
B01100110,
B01100000,
B01100000,
B01100000,
B01100110,
B00111100
},{
B00000000,
B01111100,
B01100110,
B01100110,
B01100110,
B01100110,
B01100110,
B01111100
},{
B00000000,
B01111110,
B01100000,
B01100000,
B01111100,
B01100000,
B01100000,
B01111110
},{
B00000000,
B01111110,
B01100000,
B01100000,
B01111100,
B01100000,
B01100000,
B01100000
},{
B00000000,
B00111100,
B01100110,
B01100000,
B01100000,
B01101110,
B01100110,
B00111100
},{
B00000000,
B01100110,
B01100110,
B01100110,
B01111110,
B01100110,
B01100110,
B01100110
},{
B00000000,
B00111100,
B00011000,
B00011000,
B00011000,
B00011000,
B00011000,
B00111100
},{
B00000000,
B00011110,
B00001100,
B00001100,
B00001100,
B01101100,
B01101100,
B00111000
},{
B00000000,
B01100110,
B01101100,
B01111000,
B01110000,
B01111000,
B01101100,
B01100110
},{
B00000000,
B01100000,
B01100000,
B01100000,
B01100000,
B01100000,
B01100000,
B01111110
},{
B00000000,
B01100011,
B01110111,
B01111111,
B01101011,
B01100011,
B01100011,
B01100011
},{
B00000000,
B01100011,
B01110011,
B01111011,
B01101111,
B01100111,
B01100011,
B01100011
},{
B00000000,
B00111100,
B01100110,
B01100110,
B01100110,
B01100110,
B01100110,
B00111100
},{
B00000000,
B01111100,
B01100110,
B01100110,
B01100110,
B01111100,
B01100000,
B01100000
},{
B00000000,
B00111100,
B01100110,
B01100110,
B01100110,
B01101110,
B00111100,
B00000110
},{
B00000000,
B01111100,
B01100110,
B01100110,
B01111100,
B01111000,
B01101100,
B01100110
},{
B00000000,
B00111100,
B01100110,
B01100000,
B00111100,
B00000110,
B01100110,
B00111100
},{
B00000000,
B01111110,
B01011010,
B00011000,
B00011000,
B00011000,
B00011000,
B00011000
},{
B00000000,
B01100110,
B01100110,
B01100110,
B01100110,
B01100110,
B01100110,
B00111110
},{
B00000000,
B01100110,
B01100110,
B01100110,
B01100110,
B01100110,
B00111100,
B00011000
},{
B00000000,
B01100011,
B01100011,
B01100011,
B01101011,
B01111111,
B01110111,
B01100011
},{
B00000000,
B01100011,
B01100011,
B00110110,
B00011100,
B00110110,
B01100011,
B01100011
},{
B00000000,
B01100110,
B01100110,
B01100110,
B00111100,
B00011000,
B00011000,
B00011000
},{
B00000000,
B01111110,
B00000110,
B00001100,
B00011000,
B00110000,
B01100000,
B01111110
},{
B00000000,
B00011110,
B00011000,
B00011000,
B00011000,
B00011000,
B00011000,
B00011110
},{
B00000000,
B00000000,
B01100000,
B00110000,
B00011000,
B00001100,
B00000110,
B00000000
},{
B00000000,
B01111000,
B00011000,
B00011000,
B00011000,
B00011000,
B00011000,
B01111000
},{
B00000000,
B00001000,
B00010100,
B00100010,
B01000001,
B00000000,
B00000000,
B00000000
},{
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B01111111
},{
B00000000,
B00001100,
B00001100,
B00000110,
B00000000,
B00000000,
B00000000,
B00000000
},{
B00000000,
B00000000,
B00000000,
B00111100,
B00000110,
B00111110,
B01100110,
B00111110
},{
B00000000,
B01100000,
B01100000,
B01100000,
B01111100,
B01100110,
B01100110,
B01111100
},{
B00000000,
B00000000,
B00000000,
B00111100,
B01100110,
B01100000,
B01100110,
B00111100
},{
B00000000,
B00000110,
B00000110,
B00000110,
B00111110,
B01100110,
B01100110,
B00111110
},{
B00000000,
B00000000,
B00000000,
B00111100,
B01100110,
B01111110,
B01100000,
B00111100
},{
B00000000,
B00011100,
B00110110,
B00110000,
B00110000,
B01111100,
B00110000,
B00110000
},{
B00000000,
B00000000,
B00111110,
B01100110,
B01100110,
B00111110,
B00000110,
B00111100
},{
B00000000,
B01100000,
B01100000,
B01100000,
B01111100,
B01100110,
B01100110,
B01100110
},{
B00000000,
B00000000,
B00011000,
B00000000,
B00011000,
B00011000,
B00011000,
B00111100
},{
B00000000,
B00001100,
B00000000,
B00001100,
B00001100,
B01101100,
B01101100,
B00111000
},{
B00000000,
B01100000,
B01100000,
B01100110,
B01101100,
B01111000,
B01101100,
B01100110
},{
B00000000,
B00011000,
B00011000,
B00011000,
B00011000,
B00011000,
B00011000,
B00011000
},{
B00000000,
B00000000,
B00000000,
B01100011,
B01110111,
B01111111,
B01101011,
B01101011
},{
B00000000,
B00000000,
B00000000,
B01111100,
B01111110,
B01100110,
B01100110,
B01100110
},{
B00000000,
B00000000,
B00000000,
B00111100,
B01100110,
B01100110,
B01100110,
B00111100
},{
B00000000,
B00000000,
B01111100,
B01100110,
B01100110,
B01111100,
B01100000,
B01100000
},{
B00000000,
B00000000,
B00111100,
B01101100,
B01101100,
B00111100,
B00001101,
B00001111
},{
B00000000,
B00000000,
B00000000,
B01111100,
B01100110,
B01100110,
B01100000,
B01100000
},{
B00000000,
B00000000,
B00000000,
B00111110,
B01000000,
B00111100,
B00000010,
B01111100
},{
B00000000,
B00000000,
B00011000,
B00011000,
B01111110,
B00011000,
B00011000,
B00011000
},{
B00000000,
B00000000,
B00000000,
B01100110,
B01100110,
B01100110,
B01100110,
B00111110
},{
B00000000,
B00000000,
B00000000,
B00000000,
B01100110,
B01100110,
B00111100,
B00011000
},{
B00000000,
B00000000,
B00000000,
B01100011,
B01101011,
B01101011,
B01101011,
B00111110
},{
B00000000,
B00000000,
B00000000,
B01100110,
B00111100,
B00011000,
B00111100,
B01100110
},{
B00000000,
B00000000,
B00000000,
B01100110,
B01100110,
B00111110,
B00000110,
B00111100
},{
B00000000,
B00000000,
B00000000,
B00111100,
B00001100,
B00011000,
B00110000,
B00111100
},{
B00000000,
B00001110,
B00011000,
B00011000,
B00110000,
B00011000,
B00011000,
B00001110
},{
B00000000,
B00011000,
B00011000,
B00011000,
B00000000,
B00011000,
B00011000,
B00011000
},{
B00000000,
B01110000,
B00011000,
B00011000,
B00001100,
B00011000,
B00011000,
B01110000
},{
B00000000,
B00000000,
B00000000,
B00111010,
B01101100,
B00000000,
B00000000,
B00000000
},{
B00000000,
B00001000,
B00011100,
B00110110,
B01100011,
B01000001,
B01000001,
B01111111
},{
B00000000,
B11000011,
B00000000,
B10000001,
B10000001,
B01000010,
B00100100,
B00011000,
}
};
const int IMAGES_LEN = sizeof(IMAGES)/8;
// IRrecv irrecv(RECV_PIN);
// decode_results results;
// define os pinos para controle da MATRIX DE LEDS
#define PINO_LED_DIN 52
#define PINO_LED_CLK 51
#define PINO_LED_CS 16
LedControl myMatrix = LedControl(PINO_LED_DIN, PINO_LED_CLK, PINO_LED_CS, 1);
// Inicializa o display no endereco 0x27
// LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3, POSITIVE);
/* PROJETO JOANINHA
* ROBOT SEMI AUTONOMO PARA INTERAGIR COM ADULTOS E PEQUENOS PETS
* RECIFE, JUNHO DE 2016
* AUTOR: ARNOTT RAMOS CAIADO
* VERSÃO: 00.01
*/
#define ESTADO_OUVIR 1
#define ESTADO_DORMIR 2
#define ESTADO_INTERAGIR_PARADO 3
#define ESTADO_INTERAGIR_MOVIMENTO 4
#define ESTADO_ACOMPANHAR 5
#define ESTADO_FUGIR 6
#define ESTADO_BRINCAR 7
#define ESTADO_VIGIAR 8
#define ESTADO_CUIDAR 9
#define ESTADO_PROCURAR 10
#define ESTADO_JOGAR 11
#define ESTADO_SEMFORCA 12
#define SEMBLANTE_IMPASSIVEL 100
#define SEMBLANTE_ALEGRE 101
#define SEMBLANTE_TRISTE 102
#define SEMBLANTE_DUVIDA 103
#define SEMBLANTE_SONO 104
#define SEMBLANTE_FOME 105
#define SEMBLANTE_LOUCO 106
#define SEMBLANTE_CANSADO 107
#define SEMBLANTE_CHARMOSO 108
#define SENTIDO_PARADO '1'
#define SENTIDO_FRENTE '2'
#define SENTIDO_TRAS '3'
#define SENTIDO_CIRCULO_DIREITA '4'
#define SENTIDO_CIRCULO_ESQUERDA '5'
#define SENTIDO_VIRAR_DIREITA '6'
#define SENTIDO_VIRAR_ESQUERDA '7'
#define ACELERAR '+'
#define REDUZIR '-'
#define TOCAR_MUSICA '8'
#define VELOCIDADE_MAX 200
#define VELOCIDADE_MIN 20
#define VELOCIDADE_ZERO 0
int VEL_AJUSTE_DIR=0;
int VEL_AJUSTE_ESQ=0;
/* Variaveis Globais */
int estado = ESTADO_DORMIR ;
int velocidade = VELOCIDADE_ZERO;
char sentido = SENTIDO_PARADO;
char sentido2 = SENTIDO_PARADO;
int sensorir=0;
#define RxD 19
#define TxD 18
#define PINO_ANALOGICO 15
SoftwareSerial blueToothSerial(TxD, RxD); // tx,rx
// Servo servo1;
// Servo servo2;
void setup() {
// put your setup code here, to run once:
sentido = SENTIDO_FRENTE;
velocidade = 150;
// Serial.begin(115200);
// Serial.begin (9600);
// blueToothSerial.begin(9600);
// pinMode(15, OUTPUT);
// pinMode(16, OUTPUT);
// pinMode(17, OUTPUT);
// digitalWrite(17,LOW);
// configura matriz de LEDS
myMatrix.shutdown(0, false); // habilita o display
myMatrix.setIntensity(0, 10); // define o brilho dos leds
myMatrix.clearDisplay(0); // limpa o display
// servo1.attach(9);
// servo2.attach(10);
delay(1000);
// irrecv.enableIRIn();
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
// lcd.begin (16,2);
parear_dispositivo();
Serial1.begin (9600);
}
void loop() {
// put your main code here, to run repeatedly:
int i;
float cmMsec;
float cmMsecanterior = 0;
long microsec = ultrasonic.timing();
// Read user input if available.
if ( Serial1.available())
{
sentido2 = (char) Serial1.read();
}
delay(100);
// sensorir = analogRead ( PINO_ANALOGICO );
// delay(100);
// lcd.clear ();
// lcd.setBacklight(HIGH);
// lcd.setCursor(0,0);
// lcd.print("JoAninha:");
// lcd.setCursor(10,0);
// lcd.print( sentido);
// lcd.setCursor (13,0);
// lcd.print ( velocidade );
//lcd.print( sensorir );
// lcd.setCursor(0,1);
// lcd.print("LCD e modulo I2C");
if ( sentido2 == ACELERAR || sentido2 == REDUZIR)
{
if ( sentido2 == ACELERAR )
{
velocidade = velocidade+2;
if ( velocidade > VELOCIDADE_MAX )
velocidade = VELOCIDADE_MAX;
delay(200);
sentido2=0;
}
else if (sentido2 == REDUZIR )
{
velocidade= velocidade-2;
if ( velocidade < VELOCIDADE_MIN )
velocidade = VELOCIDADE_MIN;
delay(200);
sentido2=0;
}
}
else sentido = sentido2;
cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM);
// lcd.setCursor (0,1);
// lcd.print ( cmMsec );
if ( (( cmMsec - cmMsecanterior ) * ( cmMsec - cmMsecanterior ) / cmMsec ) > 0.2 )
mostra_led_caracter ( cmMsec );
cmMsecanterior = cmMsec ;
// if ( cmMsec < 80 )
// {
//for ( i=0; i<180 ; i++)
// {
// servo1.write( i );
// servo2.write( 180-i) ;
// delay (5);
// }
// tone (buzzer, 1500 );
// delay ( cmMsec );
// noTone ( buzzer );
// for ( i=0; i<180 ; i++)
// {
// servo2.write( i );
// servo1.write( 180-i) ;
// delay(5);
// }
// Aguarda 5 segundos
//if ( cmMsec <= 100 )
//{
// tone (buzzer, 1500 );
// delay ( cmMsec );
// noTone ( buzzer );
// }
// else
// noTone (buzzer);
// }
if (mover (sentido, velocidade, cmMsec ) < 0)
{
sentido = SENTIDO_PARADO;
sentido2= sentido;
}
switch ( estado ) {
case ESTADO_OUVIR :
break;
case ESTADO_DORMIR :
break;
case ESTADO_INTERAGIR_PARADO :
break;
case ESTADO_INTERAGIR_MOVIMENTO :
break;
case ESTADO_ACOMPANHAR :
break;
case ESTADO_FUGIR :
break;
case ESTADO_BRINCAR :
break;
case ESTADO_VIGIAR :
break;
case ESTADO_CUIDAR :
break;
case ESTADO_PROCURAR :
break;
case ESTADO_JOGAR :
break;
default :
break;
}
noTone (buzzer);
}
int mover ( char sentido_movimento , int velocidade_movimento , float distancia )
{
int status = 0;
int i;
motor1.setSpeed(velocidade_movimento);
motor2.setSpeed(velocidade_movimento);
switch ( sentido_movimento ) {
case SENTIDO_FRENTE :
if ( distancia <= DIST_MINIMA ) // NAO Continuar
{
motor1.setSpeed(0);
motor2.setSpeed(0);
for ( i=1; i <= 20 ; i++ )
{
tone (buzzer, 1500);
delay(distancia);
noTone(buzzer);
delay(distancia);
}
status = -1;
} else
{
motor1.run (BACKWARD);
motor2.run (BACKWARD);
}
break;
case SENTIDO_TRAS :
motor1.run (FORWARD);
motor2.run (FORWARD);
break;
case SENTIDO_PARADO :
velocidade_movimento=0;
motor1.setSpeed(velocidade_movimento);
motor2.setSpeed(velocidade_movimento);
noTone (buzzer);
delay (100);
break;
case SENTIDO_CIRCULO_DIREITA :
motor2.run (FORWARD);
motor1.run (BACKWARD);
break;
case SENTIDO_CIRCULO_ESQUERDA :
motor1.run (FORWARD);
motor2.run (BACKWARD);
break;
case SENTIDO_VIRAR_DIREITA :
case SENTIDO_VIRAR_ESQUERDA :
break;
default :
break;
}
return ( status );
}
void parear_dispositivo()
{
blueToothSerial.begin(9600); // Configura o baud rate do bluetooth como 38400
blueToothSerial.print("\r\n+STWMOD=0\r\n"); // Configura o módulo bluetooth para trabalhar como slave
blueToothSerial.print("\r\n+STNA=ArcProg\r\n"); // Configura o nome do disopsitivo bluetooth
blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permite que outros dispositivos encontrem o módulo bluetooth
blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Desabilita a auto conexão
delay(2000); // Aguarda 2 segundos
blueToothSerial.print("\r\n+INQ=1\r\n"); // Habilita modo de paridade
delay(2000); // Aguarda 2 segundos
blueToothSerial.flush(); // Dá um flush na serial do módulo bluetooth
}
void mostra_led_caracter( int elemento )
{
int linha, coluna;
myMatrix.clearDisplay(0); // limpa a tela para o próximo quadro de animação
// delay(10);
for ( linha = 0; linha < 8 ; linha++ )
{
if ( (IMAGES[elemento][linha] & B10000000) == B10000000 ) myMatrix.setLed (0, 7, linha , true); // coluna , linha
if ( (IMAGES[elemento][linha] & B01000000) == B01000000 ) myMatrix.setLed (0, 6, linha , true); // coluna , linha
if ( (IMAGES[elemento][linha] & B00100000) == B00100000 ) myMatrix.setLed (0, 5, linha , true); // coluna , linha
if ( (IMAGES[elemento][linha] & B00010000) == B00010000 ) myMatrix.setLed (0, 4, linha , true); // coluna , linha
if ( (IMAGES[elemento][linha] & B00001000) == B00001000 ) myMatrix.setLed (0, 3, linha , true); // coluna , linha
if ( IMAGES[elemento][linha] & B00000100 ) myMatrix.setLed (0, 2, linha , true); // coluna , linha
if ( IMAGES[elemento][linha] & B00000010 ) myMatrix.setLed (0, 1, linha , true); // coluna , linha
if ( IMAGES[elemento][linha] & B00000001 ) myMatrix.setLed (0, 0, linha , true); // coluna , linha
// lcd.setCursor (13,1);
// lcd.print ( IMAGES[elemento][linha] );
// delay(100);
}
// delay(10);
}
Nenhum comentário:
Postar um comentário