Skip to content

Instantly share code, notes, and snippets.

@maxpromer
Last active July 23, 2016 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxpromer/5a138bcb71e2db7b8fcd3e74e7a2cd57 to your computer and use it in GitHub Desktop.
Save maxpromer/5a138bcb71e2db7b8fcd3e74e7a2cd57 to your computer and use it in GitHub Desktop.
/*
Name: GP2Y0A21 distance to LCD 16x2 with I2C
File: GP2Y0A21andLCD.ino
Author: IOXhop
Website: http://www.ioxhop.com/
.:: Library required ::.
LCD_I2C : https://github.com/ioxhop/LCD-I2C
SharpIR : https://github.com/guillaume-rico/SharpIR
*/
#include <LCDI2C.h>
#include <SharpIR.h>
#define IR_PIN A0
#define MODEL 1080
LCDI2C lcd(0x27); // Set i2c address
SharpIR SharpIR(IR_PIN, MODEL);
void setup() {
lcd.begin(16, 2); // Set display screen size is 16x2
lcd.setCursor(0);
lcd.print(" GP2Y0A21 ");
lcd.setCursor(0, 1);
lcd.print(" www.ioxhop.com ");
delay(3000);
lcd.clear();
lcd.setCursor(0);
lcd.print("Distancia: ");
}
void loop() {
int dis = SharpIR.distance();
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.print(dis);
lcd.print(" ");
lcd.print("cm");
lcd.print(" ");
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment