-
-
Save maxpromer/5a138bcb71e2db7b8fcd3e74e7a2cd57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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