Skip to content

Instantly share code, notes, and snippets.

#This code is the keras implementation of the above described NNdef simple_nn():
model = Sequential()
model.add(Dense(2, input_dim=1, activation='sigmoid'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='mean_squared_error', optimizer='sgd')
return model
import numpy as np
import cv2
import os
import time
from face_detection import *
from face_recognition import *
import requests
import RPi.GPIO as GPIO
####################################################################################
import RPi.GPIO as GPIO
import time
import math
BUZZER = 11 # define the BUZZER
GPIO_PIN = 12 # define the GPIO_PIN
def setup():
global pwm
print ('Program is starting...')
@Nicholas-t
Nicholas-t / BUZZER_Face_recog.py
Created March 21, 2020 03:11
part of a smart alarm system with RPi
def recognition(self,img):
face, rect = detect_faces(img)
global thres
for i in range(0, len(face)) :
label,confidence = self.face_recognizer.predict(face[i])
#print(confidence)
label_text = names[label]
if confidence > 65:
thres += 1
@Nicholas-t
Nicholas-t / ALARM_button.py
Created March 19, 2020 17:33
control alarm with button
import RPi.GPIO as GPIO
import time
import math
BUZZER = 11 # define the BUZZER
BUTTON = 12 # define the BUTTON
def setup():
global pwm
print ('Program is starting...')
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
@Nicholas-t
Nicholas-t / BUZZER_Button.py
Created March 19, 2020 17:32
control the buzzer with a button
import RPi.GPIO as GPIO
BUZZER = 11 # define the BUZZER
GPIO_PIN = 12 # define the GPIO_PIN
def setup():
print ('Program is starting...')
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
GPIO.setup(BUZZER, GPIO.OUT) # Set BUZZER's mode is output
GPIO.setup(GPIO_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set GPIO_PIN's mode is input, and pull up to high level(3.3V)
@Nicholas-t
Nicholas-t / Button_LED.py
Created March 18, 2020 17:29
Control led with a button
import RPi.GPIO as GPIO
led = 11 # define the led
button = 12 # define the button
def setup():
print ('Program is starting...')
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
GPIO.setup(led, GPIO.OUT) # Set led's mode is output
GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set button's mode is input, and pull up to high level(3.3V)
@Nicholas-t
Nicholas-t / BAR_Graph.py
Created March 18, 2020 17:25
lighting up bar graph led
import RPi.GPIO as GPIO
import time
GPIO_PINS = [11, 12, 13, 15, 16, 18, 22, 3, 5, 24]
def setup():
print ('Program is starting...')
GPIO.setmode(GPIO.BOARD)
for n_pin in GPIO_PINS:
GPIO.setup(n_pin, GPIO.OUT) # Set all GPIO_PINS' mode is output
@Nicholas-t
Nicholas-t / Blinking_LED.py
Created March 18, 2020 17:18
make LED blink with raspberry pi
import RPi.GPIO as GPIO
import time
PIN_GPIO = 11 # RPI Board pin11
def setup():
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
GPIO.setup(PIN_GPIO, GPIO.OUT) # Set PIN_GPIO's mode is output
GPIO.output(PIN_GPIO, GPIO.LOW) # Set PIN_GPIO low to off led
@Nicholas-t
Nicholas-t / RGB_LED.py
Created March 18, 2020 16:55
Controlling RGB lights
import RPi.GPIO as GPIO
import time
import random
pins = {'pin_R':11, 'pin_G':12, 'pin_B':13} # pins is a dict
def setup():
global R,G,B
print ('Program is starting ... ')
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location