Skip to content
Snippets Groups Projects
Commit b836215a authored by Thareq Yusuf's avatar Thareq Yusuf
Browse files

add sound lcd

parent cc64191d
No related merge requests found
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 17 13:25:46 2017
@author: glassbox
"""
"""Module importation"""
import serial
"""Opening of the serial port"""
try:
arduino = serial.Serial("/dev/ttyACM0",timeout=1)
except:
print('Please check the port')
"""Initialising variables"""
rawdata=[]
count=0
"""Receiving data and storing it in a list"""
while count<10:
rawdata.append(str(arduino.readline()))
count+=1
print(rawdata)
def clean(L):#L is a list
newl=[]#initialising the new list
for i in range(len(L)):
temp=L[i][2:]
newl.append(temp[:-5])
return newl
cleandata=clean(rawdata)
def write(L):
file=open("data.txt",mode='w')
for i in range(len(L)):
file.write(L[i]+'\n')
file.close()
write(cleandata)
1022
1022
1022
1022
450
1022
34
55
1022
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// ledpin and soundpin are not changed throughout the process
const int soundpin=A2;
const int threshold=997; // sets threshold value for sound sensor
void setup() {
Serial.begin(9600);
pinMode(soundpin,INPUT);
lcd.begin(16,2);
}
void loop() {
int soundsens=analogRead(soundpin); // reads analog data from sound sensor
Serial.println(soundsens);
if (soundsens>threshold) {
lcd.clear();
lcd.print("ruangan bising");
delay(2000);
}
else{
lcd.clear();
lcd.print("ruangan sepi");
delay(2000);
}
}
......@@ -19,31 +19,31 @@
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup()
{
lcd.begin (20,4); // our LCD is a 20x4, change for your LCD if needed
lcd.begin (16,2); // our LCD is a 20x4, change for your LCD if needed
// LCD Backlight ON
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home on LCD
lcd.setCursor (0,0);
//lcd.home (); // go home on LCD
lcd.print("Range Finder HC-SR04");
}
void loop()
{
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
unsigned int cm = sonar.convert_cm(uS); // Convert into centimeters
lcd.setCursor (0,1); // go to start of 2nd line
//unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
//unsigned int cm = sonar.convert_cm(uS); // Convert into centimeters
/*
lcd.setCursor (0,0); // go to start of 2nd line
lcd.print("Current Distance:");
lcd.setCursor (0,3); // go to start of 4th line
lcd.print("Ping: ");
lcd.print(cm);
lcd.print(" cm ");
lcd.setCursor (0,1); // go to start of 4th line
lcd.print("Ping: ");*/
// lcd.print(cm);
//lcd.print(" cm ");
delay(500);
//delay(500);
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment