Skip to content

Instantly share code, notes, and snippets.

@giljr
Created September 9, 2018 01:32
Show Gist options
  • Save giljr/15643e03beaba3e5938c07c485cc7d21 to your computer and use it in GitHub Desktop.
Save giljr/15643e03beaba3e5938c07c485cc7d21 to your computer and use it in GitHub Desktop.
/* Project Ardu_Serie # 45
Working w/ MultiFile Sketch - Part III - Atmega328p IC - Arduino MC
Ino File: _45_working_w_MultiFile_Sketch_03.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 headers should come after the lcd boot
#include "PIR.h"
// define the key used by the panel and buttons
int key;
// LM35 variables
float tempC;
int reading;
int tempPin = 1;
//custom degree character
byte degree[8] = {
B00110,
B01001,
B01001,
B00110,
B00000,
B00000,
B00000,
B00000,
};
void setup()
{ //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
HC.HC_Setup(11, 12);
PIR.PIR_Setup(13, 2, HIGH);
}
void loop()
{
PIR.PIR_Loop();
lcd.setCursor(0, 1); // move to the begining of the second line
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:
{
PIR.PIR_Display();
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