You are on page 1of 4

#include <LiquidCrystal.

h>

#include <Arduino.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

const int channelPinA = 2;

const int channelPinB = 3;

const int timeThreshold = 1;

long timeCounter = 0;

volatile int ISRCounter = 0;

int counter = 0;

float recorrido = 0.0;

int aux_rec = 0, num_med = 0, dif = 0, med = 0, ghost = 0;

float distancia = 0.0, dist = 0.0;

void setup()//Configuración de inicio, se ejecuta solo una vez por corrida de programa

lcd.begin(16, 2); // start the library

lcd.setCursor(0, 0); // set the LCD cursor position

lcd.print("PERFILOMETRO"); // print a simple message on the LCD

lcd.setCursor(0, 1);

lcd.print("Deza y Obeso");

delay(3000);

pinMode(channelPinA, INPUT_PULLUP);

pinMode(channelPinB, INPUT_PULLUP);

Serial.begin(9600);

//attachInterrupt(digitalPinToInterrupt(channelPinA), doEncodeA, FALLING);

attachInterrupt(digitalPinToInterrupt(channelPinB), doEncodeB, FALLING);

void loop()

if (num_med < 200)


{

lcd.clear();

lcd.setCursor(0, 0); // set the LCD cursor position

lcd.print(" Dist: ");

lcd.print(recorrido);

lcd.setCursor(0, 1);

lcd.print("N= ");

lcd.print(num_med);

lcd.print(" ");

lcd.print("Med= ");

lcd.print(med);

Serial.println(ghost);

else if(num_med == 200)

lcd.setCursor(0,0);

lcd.print(" MEDICION ");

lcd.setCursor(0,1);

lcd.print(" COMPLETA ");

if (counter != ISRCounter)

counter = ISRCounter;

delay(100);

if (aux_rec >=2)

recorrido = recorrido + 0.01178062;

aux_rec = 0;

if (counter >= 152)


{

num_med++;

distancia = analogRead(1);

for (int i = 0; i < 10; i++) {

dist = dist + distancia;

dist = dist / 10;

if (dist <= 138) //Cada cuenta representa 2mm, 138 = 25

dif = 138 - dist;

dif = dif / 2;

med = 25 - dif;

else if (dist >= 138)

dif = dist - 138;

dif = dif / 2;

med = 25 + dif;

Serial.println(med);

delay(100);

ISRCounter = 0;

void doEncodeB()

if (millis() > timeCounter + timeThreshold)

if (digitalRead(channelPinA) != digitalRead(channelPinB))

{
ISRCounter++;

aux_rec++;

else if (digitalRead(channelPinA) == digitalRead(channelPinB))

ISRCounter++;

aux_rec++;

timeCounter = millis();

You might also like