Skip to content
This repository has been archived by the owner on Nov 7, 2019. It is now read-only.

Commit

Permalink
added code for papercounter
Browse files Browse the repository at this point in the history
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
kssoz authored Jun 15, 2016
1 parent d605493 commit 9be3e6e
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions arduino/papercounter.c
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);
}

0 comments on commit 9be3e6e

Please sign in to comment.