From 539814cc52b324bd3f5d0c8cd114d62684eca57f Mon Sep 17 00:00:00 2001 From: Gafera <51031854+Gafera@users.noreply.github.com> Date: Mon, 24 Feb 2020 19:02:50 -0300 Subject: [PATCH 1/4] testeLinha.ino Teste de linha --- testeLinha.ino | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 testeLinha.ino diff --git a/testeLinha.ino b/testeLinha.ino new file mode 100644 index 0000000..2f13ab0 --- /dev/null +++ b/testeLinha.ino @@ -0,0 +1,26 @@ +#include +#define lineC 2 +#define lineD 15 +#define lineE 4 + +void setup() { + pinMode(lineE, INPUT); + pinMode(lineD, INPUT); + Serial.begin(9600); +} +int media10(int i){ + int media=0; + for(int a=0;a<1000;a++){ + media+=analogRead(i); + } + return media/1000; +} + +void loop() { + Serial.print(media10(lineD)); + Serial.print(" "); + Serial.print(media10(lineC)); + Serial.print(" "); + Serial.println(media10(lineE)); + delay(500); +} From 76cb4d027e3209fda352d36ef8bef73a2b101f47 Mon Sep 17 00:00:00 2001 From: Gafera <51031854+Gafera@users.noreply.github.com> Date: Tue, 25 Feb 2020 20:53:48 -0300 Subject: [PATCH 2/4] Update testeLinha.ino --- testeLinha.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testeLinha.ino b/testeLinha.ino index 2f13ab0..5370777 100644 --- a/testeLinha.ino +++ b/testeLinha.ino @@ -1,5 +1,5 @@ #include -#define lineC 2 +//#define lineC 2 #define lineD 15 #define lineE 4 @@ -19,7 +19,7 @@ int media10(int i){ void loop() { Serial.print(media10(lineD)); Serial.print(" "); - Serial.print(media10(lineC)); + //Serial.print(media10(lineC)); Serial.print(" "); Serial.println(media10(lineE)); delay(500); From e2b183220120624c165f61686ca88bca03766f53 Mon Sep 17 00:00:00 2001 From: Gafera <51031854+Gafera@users.noreply.github.com> Date: Tue, 25 Feb 2020 20:54:34 -0300 Subject: [PATCH 3/4] Create sharpTeste --- sharpTeste | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 sharpTeste diff --git a/sharpTeste b/sharpTeste new file mode 100644 index 0000000..c746b58 --- /dev/null +++ b/sharpTeste @@ -0,0 +1,27 @@ +# include +# define sharpFE 39 +# define sharpFD 34 +//# define sharpE 35 +# define sharpFC 36 + void setup() { + + pinMode (sharpFC, INPUT); + pinMode (sharpFE, INPUT); + pinMode (sharpFD, INPUT); +// pinMode (sharpE, INPUT); + Serial. begin ( 9600 ); + +} + + void loop() { + + if(analogRead(39) > 2000){ + Serial.println("Aproximação pelo lado direito"); + }else if(analogRead(34) > 2000){ + Serial.println("Aproximação pelo centro"); + }else if(analogRead(36) > 2000){ + Serial.println("Aproximação pela esquerda"); + } + + delay(500); +} From 3a80492bce25d792577d032c482b298cc2c4a8b6 Mon Sep 17 00:00:00 2001 From: Gafera <51031854+Gafera@users.noreply.github.com> Date: Fri, 28 Feb 2020 04:25:01 -0300 Subject: [PATCH 4/4] Primeiro commit de teste da valquiria. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Falta ajustar tempo e rotação. --- valquiriaCode | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 valquiriaCode diff --git a/valquiriaCode b/valquiriaCode new file mode 100644 index 0000000..fd7da7b --- /dev/null +++ b/valquiriaCode @@ -0,0 +1,183 @@ +#include +//#include +//#include +//#include +#include + +#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) +#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it +#endif + +BluetoothSerial SerialBT; + +char BT = 'f'; +int tempo = 4900; +char estrategia = 'f'; +char lupi = '2'; + + #define sharpE 36 + #define sharpFE 39 + #define sharpFD 34 + + #define pwmB 25 + #define b1 33 + #define b2 26 + #define stby 27 + #define a1 14 + #define a2 12 + #define pwmA 13 + //sensor de linha + #define linhaD 15 + #define linhaE 4 + + bool direc = true; + +void setup() { + pinMode(pwmB, OUTPUT); + pinMode(b1, OUTPUT); + pinMode(b2, OUTPUT); + pinMode(stby, OUTPUT); + pinMode(a1, OUTPUT); + pinMode(a2, OUTPUT); + pinMode(pwmA, OUTPUT); + pinMode(linhaE, INPUT); + pinMode(linhaD, INPUT); + pinMode(sharpE, INPUT); + pinMode(sharpFE, INPUT); + pinMode(sharpFD, INPUT); + digitalWrite(stby,1); + + SerialBT.begin("Valquiria"); //Bluetooth device name + + SerialBT.println("LIGOUUUU"); + + //enquanto serial não receber 0, troca de estretégia é possível + + while(BT != '0'){ + + if(SerialBT.available()) { + BT = SerialBT.read(); + Serial.print(BT); + } + + if(BT == '+'){ + tempo += 100; + }else if(BT == '-'){ + tempo -= 100; + }else if(BT == '<'){//escolha de direção + direc = false; + }else if(BT == '>'){//escolha de direção + direc = true; + }else if(BT == 'C'){ + SerialBT.println("Check"); + SerialBT.print("Estrategia: "); + SerialBT.println(estrategia); + SerialBT.print("Loop: "); + SerialBT.println(lupi); + SerialBT.print("Direc: "); + if(direc) SerialBT.println("direita"); + else SerialBT.println("esquerda"); + SerialBT.print("Delay: "); + SerialBT.println(tempo); + }else if(BT == '0') { + break; + }else { + if(!(BT == 13 || BT == 10 || (BT>48 && BT<58))){ + estrategia = BT; + } + if(BT>48 && BT<58){ + lupi = BT; + } + } + + } + delay(tempo); + //SerialBT.println("Start"); + //SerialBT.println(lupi); + //SerialBT.println(estrategia); + + switch (estrategia){ + case 'a': //frentao + frente(200, 200); + SerialBT.print("FRENTAAO"); + delay(500); + break; + + case 'b': //curvao + if(direc){ + esquerda(250,250); + delay(120); + frente(250, 110); + delay(1000); + } + else{ + direita(250,250); + delay(120); + frente(120, 250); + delay(1000); + } + break; + + } +} + +void loop() { + + if(sharpFD > 1000 || sharpFE > 1000){ + frente(250, 250); + }else if(sharpE > 1000){ + esquerda(250, 250); + delay(100); + }else{ + direita(250, 250); + } + + + if(linhaD > 70 || linhaE > 70){ + tras(200, 200); + delay(200); + esquerda(200, 200); + delay(200); + } + + } + /*if(SerialBT.available()){ + BT = SerialBT.read(); + if(BT == 'S') digitalWrite(stby,0); + }*/ + + + + +void tras(int pa, int pb){ + digitalWrite(b1,1); + digitalWrite(b2,0); + digitalWrite(a1,1); + digitalWrite(a2,0); + analogWrite(pwmB, pb); + analogWrite(pwmA, pa); +} +void frente(int pa, int pb){ + digitalWrite(b1,0); + digitalWrite(b2,1); + digitalWrite(a1,0); + digitalWrite(a2,1); + analogWrite(pwmB, pb); + analogWrite(pwmA, pa); +} +void esquerda(int pa, int pb){ + digitalWrite(b1,0); + digitalWrite(b2,1); + digitalWrite(a1,1); + digitalWrite(a2,0); + analogWrite(pwmB, pb); + analogWrite(pwmA, pa); + } +void direita(int pa, int pb){ + digitalWrite(b1,1); + digitalWrite(b2,0); + digitalWrite(a1,0); + digitalWrite(a2,1); + analogWrite(pwmB, pb); + analogWrite(pwmA, pa); + }