Skip to content
Snippets Groups Projects
Commit 5db78230 authored by Shahrul Kamil bin Hassan's avatar Shahrul Kamil bin Hassan
Browse files

Delete feather_main_i2c.ino

parent 1a3e64f8
No related merge requests found
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "ArnholdMesh.h"
#include <Arduino.h>
#include <string>
#include <vector>
#include "LedPanel.h"
#include "Camera.h"
openmv::rpc_scratch_buffer<256> scratch_buffer; // All RPC objects share this buffer.
openmv::rpc_i2c_master interface(0x12, 100000); //to make this more robust, consider making address and rate as constructor argument
const int BAUD_RATE = 115200;
const int MAX_SPEED = 255;
const double RESOLUTION_W = 360.0;
const double RESOLUTION_H = 240.0;
int SEEKING_SPEED = 100;
int FIND = 1; //based on the same code from openMV. Determine the color you want to find
int NOMINAL_PERCENTAGE = 60; //in percent
bool SEEKING =true;
char newPTCL = '1';
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Select motor ports
Adafruit_DCMotor *motorVertical = AFMS.getMotor(1);
Adafruit_DCMotor *motorLeft = AFMS.getMotor(2);
Adafruit_DCMotor *motorRight = AFMS.getMotor(4);
//ArnholdMesh thisNode;
Camera cam(&interface);
void setup() {
Serial.begin(BAUD_RATE);
Wire.begin();
cam.begin();
AFMS.begin(); // create with the default frequency 1.6KHz
interface.begin();
//thisNode.init();
//thisNode.mesh.onReceive(receivedCallback);
}
void loop() {
if (Serial.available()){
char test = Serial.read();
Serial.println(test);
if (test == '1' || test == '2' || test == '3' || test == '4') {
newPTCL = test;
}
}
if (newPTCL == '1'){
cam.exe_face_detection();
} else if (newPTCL == '2'){
cam.exe_color_detection(30, 100, -68, -13, 30, 127);
} else if (newPTCL == '3') {
cam.exe_qrcode_detection();
} else if (newPTCL == '4') {
cam.exe_led_detection();
}
// if (buff[0] == 0){
// //do nothing
// } else if (buff[0] == 'n'){ //if we didn't receive data or the data says no blob
// //This should set the vertical motor to produce enough trust for it to stay afloat
// //the left and right motor should turn the blimp as it seek for new blob
// if (SEEKING){
// motorVertical->setSpeed(0);
// motorVertical->run(FORWARD);
// // turn on motor
// motorVertical->run(RELEASE);
// motorLeft->setSpeed(SEEKING_SPEED*NOMINAL_PERCENTAGE/100.0);
// motorLeft->run(FORWARD);
// motorRight->setSpeed(SEEKING_SPEED*NOMINAL_PERCENTAGE/100.0);
// motorRight->run(BACKWARD);
// } else {
// motorVertical->setSpeed(0);
// motorVertical->run(FORWARD);
// // turn on motor
// motorVertical->run(RELEASE);
// motorLeft->setSpeed(0);
// motorLeft->run(FORWARD);
// motorRight->setSpeed(0);
// motorRight->run(BACKWARD);
// }
// } else {
// int i = 0;
// while (buff[i] != 'e'){ //while we are not at the end of the data
// String temp = String(buff[i]);
// int code = temp.toInt();
// if (code == FIND){ //if the desired color that we want to track is in the data
// //light up based on the position data specified
// String horizontal = String(buff[i+1]) + String(buff[i+2]) + String(buff[i+3]);
// int x = horizontal.toInt();
// String vertical = String(buff[i+4]) + String(buff[i+5]) + String(buff[i+6]);
// int y = vertical.toInt();
//
// //Planning for motor speed
// int dy = y - RESOLUTION_H/2.0;
// int dx = x - RESOLUTION_W/2.0;
// int y_speed = abs(dy/(RESOLUTION_H/2.0))*MAX_SPEED*NOMINAL_PERCENTAGE/100.0;
// int x_speed = abs(dx/(RESOLUTION_W/2.0))*MAX_SPEED*NOMINAL_PERCENTAGE/100.0;
// int lockon_speed = MAX_SPEED*NOMINAL_PERCENTAGE/200.0;
// //Serial.print("y value: ");
// //Serial.println(y);
// //Serial.print("velocity: ");
// //Serial.println(velocity);
// if (dy < 0) {
// //Serial.println("up");
// motorVertical->setSpeed(y_speed);
// motorVertical->run(BACKWARD);
// } else {
// //Serial.println("down");
// motorVertical->setSpeed(y_speed);
// motorVertical->run(FORWARD);
// }
// if (dx < 0) { //
// motorRight->setSpeed(SEEKING_SPEED);
// motorRight->run(BACKWARD);
// motorLeft->setSpeed(min(255, SEEKING_SPEED + x_speed)); //this need to be higher
// motorLeft->run(BACKWARD);
// } else {
// motorRight->setSpeed(min(255, SEEKING_SPEED + x_speed)); //this need to be higher
// motorRight->run(BACKWARD);
// motorLeft->setSpeed(SEEKING_SPEED);
// motorLeft->run(BACKWARD);
// }
// break; //we only track one blob
// } else { //if the blob is not the desired color, check the next blob
// i = i + 7;
// }
// }
// }
// //End of Demo 3
delay(1); // Don't loop to quickly.
//thisNode.update();
}
//static void receivedCallback( uint32_t from, String &msg ) {
// //This function is where the translation
// Serial.println(msg);
// if (msg[0] == '0'){
// for (int i = 1; i < 6; i++){
// int code = msg[1] - '0' ;
// if (code == i){
// FIND = code;
// Serial.print("the code is: ");
// Serial.println(FIND);
// }
// }
// } else if (msg[0] == '1'){ //speed change
// String k = msg.substring(1);
// int v = k.toInt();
// if (v < 100){
// NOMINAL_PERCENTAGE = v;
// }
// } else if (msg[0] == '2') {
// if (msg[1] == '0'){
// SEEKING = false;
// } else if (msg[1] == '1') {
// SEEKING = true;
// }
// }
// String sendConfirmation = "R";
// thisNode.sendTo(from, sendConfirmation);
//}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment