// BBeam Sensor Code
#include <OneWire.h> // LCD Wire
#include <LiquidCrystal_I2C.h> // LCD
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
#define LEDPIN 13
#define SENSORPIN 4
// variables will change:
int sensorState = 0, lastState=0; 4r // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(LEDPIN, OUTPUT);
// initialize the sensor pin as an input:
pinMode(SENSORPIN, INPUT);
digitalWrite(SENSORPIN, HIGH); // turn on the pullup
Serial.begin(9600);
lcd.init();
lcd.setBacklight(HIGH); // NOTE: You can turn the backlight off by setting it to LOW instead of HIGH
lcd.begin(16, 2);
}
void loop(){
// read the state of the pushbutton value:
sensorState = digitalRead(SENSORPIN);
// check if the sensor beam is broken
// if it is, the sensorState is LOW:
if (sensorState == LOW) {
// BB sensor is broken:
lcd.setCursor(0,0);
lcd.print("broken text here");
delay(1000); // delay of how much it loops
}
else {
// if the sensor beam isn't broken it will be on HIGH:
// BB sensor isn't broken
lcd.clear();
lcd.setCursor(0,0);
lcd.print("text here");
delay(1000); // delay of how much it loops
}
if (sensorState && !lastState) {
Serial.println("Unbroken");
} // the state of the sensors
if (!sensorState && lastState) {
Serial.println("Broken");
}
lastState = sensorState;
}e;
}
Comments