From 1940dfb579afb889826b8d9364082f79ff81dfe7 Mon Sep 17 00:00:00 2001 From: YulianSalo <39466050+YulianSalo@users.noreply.github.com> Date: Sat, 27 Oct 2018 14:27:46 +0300 Subject: [PATCH 1/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6f47d18..9946049 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # gpio -GPIO works for Raspberry PI +GPIO that works for Raspberry Pi From 2546ea622943df5479fee54b3e0b09a294d61778 Mon Sep 17 00:00:00 2001 From: YulianSalo <39466050+YulianSalo@users.noreply.github.com> Date: Sat, 27 Oct 2018 14:36:01 +0300 Subject: [PATCH 2/5] distance_and_led_sensors In order to run this program you need to connect Ultrasonic Distance Sensor (I've used HC-SR04), LED and reistors. --- distance_and_led_sensors.py | 67 +++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 distance_and_led_sensors.py diff --git a/distance_and_led_sensors.py b/distance_and_led_sensors.py new file mode 100644 index 0000000..2ad0c3a --- /dev/null +++ b/distance_and_led_sensors.py @@ -0,0 +1,67 @@ +import RPi.GPIO as GPIO +import time + +#GPIO Mode (BOARD / BCM) +GPIO.setmode(GPIO.BCM) + +#set GPIO Pins +GPIO_TRIGGER = 23 +GPIO_ECHO = 24 +LED_1 = 4 + +#set GPIO direction (IN / OUT) +GPIO.setup(GPIO_TRIGGER, GPIO.OUT) +GPIO.setup(GPIO_ECHO, GPIO.IN) +GPIO.setup(LED_1, GPIO.OUT) + +def led(): + GPIO.output(LED_1,True) ## Turn on Led + time.sleep(1) ## Wait for one second + GPIO.output(LED_1,False) ## Turn off Led + time.sleep(1) + +def distance(): + # set Trigger to HIGH + GPIO.output(GPIO_TRIGGER, True) + + # set Trigger after 0.01ms to LOW + time.sleep(0.00001) + GPIO.output(GPIO_TRIGGER, False) + + StartTime = time.time() + StopTime = time.time() + + # save StartTime + while GPIO.input(GPIO_ECHO) == 0: + StartTime = time.time() + + # save time of arrival + while GPIO.input(GPIO_ECHO) == 1: + StopTime = time.time() + + # time difference between start and arrival + TimeElapsed = StopTime - StartTime + # multiply with the sonic speed (34300 cm/s) + # and divide by 2, because there and back + distance = (TimeElapsed * 34300) / 2 + + return distance +############################################################## + + + + +if __name__ == '__main__': + try: + while True: + dist = distance() + print ("Measured Distance = %.1f cm" % dist) + time.sleep(0.01) + if dist <25: + led() + + + # Reset by pressing CTRL + C + except KeyboardInterrupt: + print("Measurement stopped by User") + GPIO.cleanup() \ No newline at end of file From 104a8954e0320ecc47a02679db0110f2512ac5a5 Mon Sep 17 00:00:00 2001 From: YulianSalo <39466050+YulianSalo@users.noreply.github.com> Date: Sat, 27 Oct 2018 22:19:11 +0300 Subject: [PATCH 3/5] Minor code update and file name update suggestion --- cool.py | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/cool.py b/cool.py index e64b899..d15f901 100644 --- a/cool.py +++ b/cool.py @@ -30,49 +30,53 @@ def off (): GPIO.output(13, False) return 0 -try: +if __name__ == '__main__': + try: state = off() + while True: fo = open("/sys/class/thermal/thermal_zone0/temp") str = fo.read() fo.close() print(str) - temp = int(str)/1000 + temp = int(st + r)/1000 print(temp) if state == 0: if temp >= midtemp: state = lowon() + if state == 1: if temp >= hightemp: state = highon() else: if temp <= midtemp - delta: state = off () + if state == 2: if temp <= hightemp - delta: state = lowon() print(state) - time.sleep(15) - - -#try: + + time.sleep(15) + #try: #while True: - #char = screen.getch() - #print chr(char) - #if char == ord('q'): - #break - #elif char == ord('1'): - #GPIO.output(11, False) - #GPIO.output(13, False) - #elif char == ord('2'): - #GPIO.output(11, True) - #GPIO.output(13, False) - #elif char == ord('3'): - #GPIO.output(11, True) - #GPIO.output(13, True) - #time.sleep(.5) + #char = screen.getch() + #print chr(char) + #if char == ord('q'): + #break + #elif char == ord('1'): + #GPIO.output(11, False) + #GPIO.output(13, False) + #elif char == ord('2'): + #GPIO.output(11, True) + #GPIO.output(13, False) + #elif char == ord('3'): + #GPIO.output(11, True) + #GPIO.output(13, True) + #time.sleep(.5) -finally: - curses.nocbreak(); screen.keypad(0); curses.echo() - curses.endwin() - GPIO.cleanup() + finally: + curses.nocbreak(); screen.keypad(0); curses.echo() + curses.endwin() + GPIO.cleanup() From fad93fb38b0822f448b7196760ed563eefb3edb6 Mon Sep 17 00:00:00 2001 From: YulianSalo <39466050+YulianSalo@users.noreply.github.com> Date: Sat, 27 Oct 2018 22:21:47 +0300 Subject: [PATCH 4/5] minor code update and name change suggestion --- cool.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cool.py b/cool.py index d15f901..3987231 100644 --- a/cool.py +++ b/cool.py @@ -39,9 +39,9 @@ def off (): str = fo.read() fo.close() print(str) - temp = int(st - r)/1000 + temp = int(str)/1000 print(temp) + if state == 0: if temp >= midtemp: state = lowon() From 9a145b8611c2704ffce608d05bb70f861449f1d2 Mon Sep 17 00:00:00 2001 From: YulianSalo <39466050+YulianSalo@users.noreply.github.com> Date: Wed, 23 Jan 2019 18:05:02 +0200 Subject: [PATCH 5/5] students.py Python file to commit, clean and see data in database --- SchoolProject/students.py | 114 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 SchoolProject/students.py diff --git a/SchoolProject/students.py b/SchoolProject/students.py new file mode 100644 index 0000000..aa17986 --- /dev/null +++ b/SchoolProject/students.py @@ -0,0 +1,114 @@ +from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String, inspect +engine = create_engine('sqlite:///college.db') + +meta = MetaData() + +students = Table( + 'students', meta, + Column('id', Integer, primary_key = True), + Column('name', String), + Column('lastname', String) + Column('student_id', String), +) +meta.create_all(engine) + +class Student(object): + """docstring for ClassName""" + def __init__(self, name, lastName, studentId): + self.name = name + self.lastName = lastName + self.studentId = studentId + + def getName(self): + return self.name + + def getLastName(self): + return self.lastName + + def getStudentId(self): + return self.studentId + + def setName(name): + self.name = name + + def setLastName(lastName): + self.lastName = lastName + + def setStudentId(studentId): + self.studentId = studentId + + def __str__(self): + return 'Name: {}: Surname: {} StudentID: {}'.format(self.name, self.lastName, self.studentId) + +def main(): + + print("""Welcome! Please choose an action to start: + 1. Input data. + 2. Clear data. + 3. See data. \n""") + action = int(input("...")) + + conn = engine.connect() + + while action != 1 or action !=2 or action !=3: + if action == 1: + + inputListLength = int(input("Please enter length of inputList: ")) + inputList = [] + #s = [] + + conn = engine.connect() + + for i in range(inputListLength): + inputList.append("-") + #s.append(" ") + + for i in range(inputListLength): + sName = input("{}. Input S_name: ".format(i+1)) + sLastName = input("{}. Input S_LASTNAME:".format(i+1)) + sStudentID = input("{}. Input StudentID:".format(i+1)) + inputList[i] = Student(sName, sLastName, sStudentID) + conn.execute(students.insert(), [ + {'name': sName, 'lastname' : sLastName, 'student_id' : sStudentID }, + + ]) + print ("\n") + + + s = students.select() + result = conn.execute(s) + + for row in result: + print (row) + + elif action == 2: + + students.drop(engine) + inspector = inspect(engine) + + if inspector == True: + print("Your data was cleared successfully.") + else: + print("Something went wrong.") + + break + + elif action == 3: + + s = students.select() + result = conn.execute(s) + + for row in result: + + print(row) + + break + + else: + + print("Your input is not correct. Please try again.") + + +if __name__ == '__main__': + main() +