This repository has been archived by the owner on Nov 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is code provided by dino0815 to messure the filling level of the toilet paper dispenser of our klobot. It needs more adaptation for the special purpose of reporting lowlevel warnings to our space cybernetics. This way it is desgined to feed an lcd with a distance in cm.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <Wire.h> | ||
#include <LiquidCrystal_I2C.h> | ||
|
||
LiquidCrystal_I2C lcd(0x3F,20,4); // set the LCD address to 0x20 for | ||
a 16 chars and 2 line display | ||
|
||
const int trigger = 10; | ||
const int echo = 9; | ||
|
||
// const float durchmesser = 3.8; | ||
// const float pfand = 0.25; | ||
|
||
// unsigned long lastAktion = 0; | ||
// unsigned long timeout = 10000; | ||
|
||
float distance; | ||
|
||
int count = 0; | ||
int old_state = 0; // 0 = Low, 1 = High | ||
|
||
void setup(){ | ||
Serial.begin(9600); | ||
pinMode(trigger,OUTPUT); | ||
pinMode(echo,INPUT); | ||
|
||
lcd.init(); // initialize the lcd | ||
|
||
// Print a message to the LCD. | ||
lcd.backlight(); | ||
lcd.print("Rollen Messung... "); | ||
} | ||
|
||
void loop(){ | ||
//Initialize the sensor | ||
digitalWrite(trigger,LOW); | ||
delayMicroseconds(5); | ||
//We start the measurements | ||
//We send out a signal activating the trigger output for 10 microseconds | ||
digitalWrite(trigger,HIGH); | ||
delayMicroseconds(10); | ||
digitalWrite(trigger,LOW); | ||
//We acquire the data and We convert the measurement to meters | ||
//We measure the pulse width | ||
//When the pin is HIGH It will measure the amount of time until it is LOW) | ||
distance=pulseIn(echo,HIGH); | ||
distance=distance*0.01657; | ||
|
||
//We send the measured data through the serial port and to the LCD display | ||
lcd.setCursor ( 0, 1 ); // go to the first line | ||
lcd.print(distance); | ||
lcd.print("cm "); | ||
Serial.print(distance); | ||
Serial.print("cm "); | ||
|
||
delay(200); | ||
} |