From 60d21aa7ede683477a5efde42efa16be7589567d Mon Sep 17 00:00:00 2001 From: MdelgadoL Date: Thu, 18 Nov 2021 07:15:06 -0600 Subject: [PATCH] Update ProfessionalLineFollower.ino updated --- .../ProfessionalLineFollower.ino | 125 ++++++++++++++---- 1 file changed, 98 insertions(+), 27 deletions(-) diff --git a/ProfessionalLineFollower/ProfessionalLineFollower.ino b/ProfessionalLineFollower/ProfessionalLineFollower.ino index 21e3c36..bebfbe3 100644 --- a/ProfessionalLineFollower/ProfessionalLineFollower.ino +++ b/ProfessionalLineFollower/ProfessionalLineFollower.ino @@ -4,6 +4,7 @@ #include #include + //PB11 SDA2 //PB11 SCL2 #define SCREEN_WIDTH 128 // OLED display width, in pixels @@ -13,7 +14,7 @@ TwoWire WIRE2 (2,I2C_FAST_MODE); #define Wire WIRE2 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); -String valor; +String cad; #define A0 PA0 #define A1 PA1 //POT 1 DER @@ -26,6 +27,7 @@ String valor; #define A8 PB1 //POT 1 IZQ #define A9 PB0 //POT 2 IZQ + #define button PB12 #define ledGreenLeft PA8 @@ -35,10 +37,10 @@ String valor; #define ledRedRight PB6 #define ledBlueRight PB7 -int pots[]={A1,A2,A8,A9}; //Pines de los potenciometros -int maxPot[]={100,100,100,100}; //Valores maximos a mapear los potenciometros -int potNumber=1; //cantidad de potenciometros +int valores[16]; //Arreglo para obtener los datos de los sensores +int numSensores=16; +int umbral[16]; //Arreglo con el umbral de cada sensor boolean start=false; @@ -71,49 +73,118 @@ void setup() { pinMode(ledBlueRight,OUTPUT); pinMode(ledRedRight,OUTPUT); pinMode(ledGreenRight,OUTPUT); - + while(!Serial){} +calibracion(); } void loop() { - valor=""; - for(int x=0;x<16;x++){ +/* + leerRaw(); + for(int x=0;x "); + pos=map(pos,0,1600, -255,255); + Serial.println(pos); + + + pantalla(cad); + delay(100); + +} + +void getPosicion(){ + leerDigital(); + for(int x=0;x4000){ - valor+="0"; + if(analogRead(A5)>umbral[x]){ + valores[x]=(x+1)*100; + suma+=valores[x]; + contador++; }else{ - valor+="-"; + valores[x]=0; } - // Serial.print(v); - // Serial.print("\t"); } - Serial.println(valor); - pantalla(valor); + return suma/contador; +} + +void calibracion(){ + int min[]={5000,5000,5000,5000,5000,5000,5000,5000,5000,5000,5000,5000,5000,5000,5000,5000}; + int max[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + digitalWrite(ledGreenLeft,HIGH); + digitalWrite(ledGreenRight,HIGH); + for(int y=0;y<800;y++){ + for(int x=0;xv){ + min[x]=v; + } + if(max[x]