Skip to content

Instantly share code, notes, and snippets.

@giljr
Created September 9, 2018 01:25
Show Gist options
  • Save giljr/b87eca3a003f80345bae45f0a052fa93 to your computer and use it in GitHub Desktop.
Save giljr/b87eca3a003f80345bae45f0a052fa93 to your computer and use it in GitHub Desktop.
/* Project Ardu_Serie # 45
Working w/ MultiFile Sketch - Part II - Atmega328p IC - Arduino MC
Ino File: _45_working_w_MultiFile_Sketch_02.ino
*/
#include <LiquidCrystal.h>
#include <DFR_LCD_Keypad.h> //Sample using https://www.dfrobot.com library
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// initialise the keypad
DFR_LCD_Keypad keypad(A0, &lcd);
#include "HC_SR04.h" // Warning: this header should come after the lcd boot
// define the key value used by the panel and buttons
int key;
// TMP36 variables
float tempC;
int reading;
int tempPin = 1;
//custom degree character
byte degree[8] = {
B00110,
B01001,
B01001,
B00110,
B00000,
B00000,
B00000,
B00000,
};
int ledPin = 13; //PIR variables
int pirPin = 2;
int pirState = LOW;
void setup()
{
//TMP36 - Read Note on case KEY_DOWN below;)
//analogReference(INTERNAL);
//LCD setup
lcd.createChar(0, degree);
lcd.begin(16, 2); // start the library
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Push the buttons"); // print a simple message
pinMode(ledPin, OUTPUT); //PIR Setup
pinMode(pirPin, INPUT);
HC.HC_Setup(11, 12);
}
void loop()
{
int pirValue = digitalRead(pirPin); //PIR Loop
if (pirValue == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
//lcd.print("Motion ended! ");
pirState = LOW;
}
lcd.setCursor(0, 1); // move to the begining of the second line
//lcd_key = read_LCD_buttons(); // read the buttons
key = keypad.read_key(); // read the buttons
// print the key selection to the LCD
switch (key) // depending on which button was pushed, we perform an action
{
case KEY_RIGHT:
{
if (pirState == HIGH) {
lcd.print("Motion detected!");
};
if (pirState == LOW) {
lcd.print("Motion ended! ");
}
break;
}
case KEY_LEFT:
{
HC.HC_Loop();
HC.HC_Display();
break;
}
case KEY_DOWN:
{
reading = analogRead(tempPin);
lcd.setCursor(0, 1); // move to the begining of the second line
float voltage = reading * 5.0; // converting that reading to voltage
voltage /= 1024.0;
// now print out the temperature
tempC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage - 500mV) times 100)
lcd.print(tempC, 1);
lcd.setCursor(4, 2); // move cursor to second line "1" and 4 spaces over
lcd.write((byte)0); // display custom degree symbol
lcd.print("C");
delay(100);
break;
}
case KEY_SELECT:
{
lcd.print("Thank you!I'm J3");
break;
}
case KEY_NONE:
{
lcd.print(" ");
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment