Hi. I've built the Adabox 002 robot (I'm doing this with a group of 3rd and 4th graders) and we;re having a few coding issues. The big one at the moment is that I can get the bot to drive, or I cn make the pezio 'sing' but I can' t get the bot to drive and the make it sing by pressing "1" on the controller
(code)#include <string.h>
#include <Arduino.h>
#include <SPI.h>
#if not defined (VARIANT_ARDUINO_DUE_X)
#include <SoftwareSerial.h>
#endif
#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
#include "Adafruit_BluefruitLE_UART.h"
#include "BluefruitConfig.h"
#include <Wire.h>
#include <Adafruit_MotorShield.h>
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// And connect 2 DC motors to port M3 & M4 !
Adafruit_DCMotor *L_MOTOR = AFMS.getMotor(3);
Adafruit_DCMotor *R_MOTOR = AFMS.getMotor(4);
//Name your RC here
String BROADCAST_NAME = "Adafruit Black Robot Rover";
String BROADCAST_CMD = String("AT+GAPDEVNAME=" + BROADCAST_NAME);
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);
#define toneC 1911
#define toneC1 1804
#define toneD 1703
#define toneEb 1607
#define toneE 1517
#define toneF 1432
#define toneF1 1352
#define toneG 1276
#define toneAb 1204
#define toneA 1136
#define toneBb 1073
#define toneB 1012
#define tonec 955
#define tonec1 902
#define toned 851
#define toneeb 803
#define tonee 758
#define tonef 716
#define tonef1 676
#define toneg 638
#define toneab 602
#define tonea 568
#define tonebb 536
#define toneb 506
#define tonep 0
int speaker = A1;
long vel = 20000;
boolean hasplayed = false;
// A small helper
void error(const __FlashStringHelper*err) {
Serial.println(err);
while (1);
}
// function prototypes over in packetparser.cpp
uint8_t readPacket(Adafruit_BLE *ble, uint16_t timeout);
float parsefloat(uint8_t *buffer);
void printHex(const uint8_t * data, const uint32_t numBytes);
// the packet buffer
extern uint8_t packetbuffer[];
char buf[60];
//
/*!
@brief Sets up the HW an the BLE module (this function is called
automatically on startup)
*/
//
void setup(void)
{
Serial.begin(9600);
AFMS.begin(); // create with the default frequency 1.6KHz
// turn on motors
L_MOTOR->setSpeed(0);
L_MOTOR->run(RELEASE);
R_MOTOR->setSpeed(0);
R_MOTOR->run(RELEASE);
Serial.begin(115200);
Serial.println(F("Adafruit Bluefruit Robot Controller Example"));
Serial.println(F("-----------------------------------------"));
/* Initialize the module */
BLEsetup();
pinMode(speaker, OUTPUT);
L_MOTOR->setSpeed(155);
R_MOTOR->setSpeed(155);
}
int melod[] = {tonec, toneG, toneE, toneA, toneB, toneBb, toneA, toneG, tonee, toneg, tonea, tonef, toneg, tonee, tonec, toned, toneB};
int ritmo[] = {18, 18, 18, 12, 12, 6, 12, 8, 8, 8, 12, 6, 12, 12, 6, 6, 6};
void loop(void)
{
// read new packet data
uint8_t len = readPacket(&ble, BLE_READPACKET_TIMEOUT);
readController();
}
bool readController(){
// Buttons
if (packetbuffer[1] == 'B') {
uint8_t buttnum = packetbuffer[2] - '0';
boolean pressed = packetbuffer[3] - '0';
// Serial.println(buttnum);
if (pressed) {
if(buttnum == 1){
if (hasplayed == true){ return;}
for (int i=0; i<17; i++) {
int tom = melod*;*
_ int tempo = ritmo*;_
_ long tvalue = tempo * vel;_
_ tocar(tom, tvalue);_
_ delayMicroseconds(1000);_
_ } //delay(1000);_
_ hasplayed = true;_
_ }*_
* if(buttnum == 2){*
* }*
* if(buttnum == 3){*
* }*
* if(buttnum == 4){*
* }*
* if(buttnum == 5){*
* L_MOTOR->run(FORWARD);
R_MOTOR->run(FORWARD);
_ }*_
* if(buttnum == 6){*
* L_MOTOR->run(BACKWARD);
R_MOTOR->run(BACKWARD);
_ }*_
* if(buttnum == 7){*
* L_MOTOR->run(RELEASE);
R_MOTOR->run(FORWARD);
_ }*_
* if(buttnum == 8){*
* L_MOTOR->run(FORWARD);
R_MOTOR->run(RELEASE);
_ } _
_ }_
_ else {_
L_MOTOR->run(RELEASE);
R_MOTOR->run(RELEASE);
_ hasplayed = false;_
_ }_
_}_
_}_
void BLEsetup(){
_ Serial.print(F("Initialising the Bluefruit LE module: "));_
if ( !ble.begin(VERBOSE_MODE) )
_ {_
_ error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));_
_ }_
_ Serial.println( F("OK!") );_
_ / Perform a factory reset to make sure everything is in a known state /_
_ Serial.println(F("Performing a factory reset: "));_
_ if (! ble.factoryReset() ){_
_ error(F("Couldn't factory reset"));_
_ }_
_ //Convert the name change command to a char array*_
* BROADCAST_CMD.toCharArray(buf, 60);
_ //Change the broadcast device name here!_
_ if(ble.sendCommandCheckOK(buf)){_
_ Serial.println("name changed");_
_ }_
_ delay(250);_
_ //reset to take effect*_
* if(ble.sendCommandCheckOK("ATZ")){*
* Serial.println("resetting");*
* }*
* delay(250);*
* //Confirm name change*
* ble.sendCommandCheckOK("AT+GAPDEVNAME");*
_ /* Disable command echo from Bluefruit /_
_ ble.echo(false);_
_ Serial.println("Requesting Bluefruit info:");_
_ / Print Bluefruit information /_
_ ble.info();_
_ Serial.println(F("Please use Adafruit Bluefruit LE app to connect in Controller mode"));_
_ Serial.println(F("Then activate/use the sensors, color picker, game controller, etc!"));_
_ Serial.println();_
_ ble.verbose(false); // debug info is a little annoying after this point!_
_ / Wait for connection /_
_ while (! ble.isConnected()) {_
_ delay(500);_
_ }_
_ Serial.println(F("*****************"));_
_ // Set Bluefruit to DATA mode*_
* Serial.println( F("Switching to DATA mode!") );*
* ble.setMode(BLUEFRUIT_MODE_DATA);
_ Serial.println(F("*****************"));_
_}_
void tocar(int tom, long tempo_value) {
long tempo_gasto = 0;
while (tempo_gasto < tempo_value) {
_ digitalWrite(speaker, HIGH);_
_ delayMicroseconds(tom / 2);_
_ digitalWrite(speaker, LOW);_
_ delayMicroseconds(tom/2); _
tempo_gasto += tom;
_ }_
_} (/code)*_
THe error message is went on for pages!
I'm lost! Please help.