diff --git a/README.md b/README.md index 90629eb..aa8216c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ # gpio -GPIO works for Raspberry PI + +GPIO that works for Raspberry Pi + # cool.py The simplest way to control a cooler speed. You'll need only two things: stepdown DC-DC converter and relay shield module. + 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() + diff --git a/cool.py b/cool.py index 1126768..a15e5fa 100644 --- a/cool.py +++ b/cool.py @@ -16,13 +16,66 @@ def highon (): GPIO.output(13, True) return 2 +def off (): + GPIO.output(11, False) + GPIO.output(13, False) + return 0 + +if __name__ == '__main__': + try: + state = off() + + try: state = lowon() + while True: fo = open("/sys/class/thermal/thermal_zone0/temp") str = fo.read() fo.close() temp = int(str)/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: + #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) + + finally: + curses.nocbreak(); screen.keypad(0); curses.echo() + curses.endwin() + GPIO.cleanup() + if state == 1: if temp >= hightemp: state = highon() @@ -34,3 +87,4 @@ def highon (): finally: GPIO.cleanup() + 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