def setup(): ADC0834.setup() GPIO.setmode(GPIO.BCM) GPIO.setup(ledPin, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(buzzPin, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(Joy_BtnPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) LCD1602.init(0x27, 1)
def loop(): while True: x_val = ADC0834.getResult(0) y_val = ADC0834.getResult(1) Btn_val = GPIO.input(BtnPin) print('X: %d Y: %d Btn: %d' % (x_val, y_val, Btn_val)) time.sleep(0.2)
def config(): GPIO.setmode(GPIO.BCM) ADC0834.setup() # setup_light() therm.setup_files(number_of_lines) weather.setup_files(number_of_lines)
def loop(): while True: x_val = ADC0834.getResult(0) y_val = ADC0834.getResult(1) btn_val = GPIO.input(button) print('X: %d Y: %d Btn: %d' % (x_val, y_val, btn_val)) xMappedInput = _map( x_val, 0, 255, 2, 12) yMappedInput = _map( y_val, 0, 255, 2, 12) btnMappedInput = _map( btn_val, 0, 1, 10, 13) print(x_val, y_val, btnMappedInput) setAngles(xMappedInput, yMappedInput, btnMappedInput)
def setup(): global led_val # Set the GPIO modes to BCM Numbering GPIO.setmode(GPIO.BCM) # Set all LedPin's mode to output and initial level to High(3.3v) GPIO.setup(LedPin, GPIO.OUT, initial=GPIO.HIGH) ADC0834.setup() # Set led as pwm channel and frequece to 2KHz led_val = GPIO.PWM(LedPin, 2000) # Set all begin with value 0 led_val.start(0)
def setup(): global p_M1, p_M2 ADC0834.setup() GPIO.setmode(GPIO.BCM) GPIO.setup(MotorPin1, GPIO.OUT) GPIO.setup(MotorPin2, GPIO.OUT) p_M1 = GPIO.PWM(MotorPin1, 2000) p_M2 = GPIO.PWM(MotorPin2, 2000) p_M1.start(0) p_M2.start(0) GPIO.setup(MotorEnable, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(BtnPin, GPIO.IN)
def get_joystick_value(): x_val = ADC0834.getResult(1) y_val = ADC0834.getResult(2) if(x_val > 200): return 1 elif(x_val < 50): return -1 elif(y_val > 200): return -10 elif(y_val < 50): return 10 else: return 0
def temperature(): analogVal = ADC0834.getResult() Vr = 5 * float(analogVal) / 255 Rt = 10000 * Vr / (5 - Vr) temp = 1 / (((math.log(Rt / 10000)) / 3950) + (1 / (273.15 + 25))) Cel = temp - 273.15 Fah = Cel * 1.8 + 32 return Cel
def main(number_of_lines, date): temp_val_raw = ADC0834.getResult(0) Vr = 5 * float(temp_val_raw) / 255 Rt = 10000 * Vr / (5 - Vr) temp = 1 / (((math.log(Rt / 10000)) / 3950) + (1 / (273.15 + 25))) temp_val = round(temp - 273.15) time.sleep(1) lum_val = round((ADC0834.getResult(2) * -1) + 255) weather_temp = open( "/home/bertrand/workspace/rasp/static/data/therm_inside.csv", "a+") weather_temp.write("%s,%s\n" % (date, temp_val)) num_lines_temp = sum(1 for line in open( '/home/bertrand/workspace/rasp/static/data/therm_inside.csv')) if num_lines_temp > number_of_lines: with open('/home/bertrand/workspace/rasp/static/data/therm_inside.csv', 'r') as fin: data = fin.read().splitlines(True) with open('/home/bertrand/workspace/rasp/static/data/therm_inside.csv', 'w') as fout: fout.writelines(data[1:]) weather_temp.close() weather_temp_total = open( "/home/bertrand/workspace/rasp/static/data/therm_inside_total.csv", "a+") weather_temp_total.write("%s,%s\n" % (date, temp_val)) weather_temp_total.close() photo = open("/home/bertrand/workspace/rasp/static/data/photo.csv", "a+") photo.write("%s,%s\n" % (date, lum_val)) num_lines_photo = sum(1 for line in open( '/home/bertrand/workspace/rasp/static/data/photo.csv')) if num_lines_photo > number_of_lines: with open('/home/bertrand/workspace/rasp/static/data/photo.csv', 'r') as fin: data = fin.read().splitlines(True) with open('/home/bertrand/workspace/rasp/static/data/photo.csv', 'w') as fout: fout.writelines(data[1:]) photo.close() photo_total = open( "/home/bertrand/workspace/rasp/static/data/photo_total.csv", "a+") photo_total.write("%s,%s\n" % (date, lum_val)) photo_total.close() return
def loop(): while True: analogVal = ADC0834.getResult() Vr = 5 * float(analogVal) / 255 Rt = 10000 * Vr / (5 - Vr) temp = 1/(((math.log(Rt / 10000)) / 3950) + (1 / (273.15+25))) Cel = temp - 273.15 Fah = Cel * 1.8 + 32 print ('Celsius: %.2f C Fahrenheit: %.2f F' % (Cel, Fah)) time.sleep(0.2)
def getValue(): analogVal = ADC0834.getResult() if analogVal > 100: move.clockwise() sleep(5) move.stop() elif analogVal < 20: move.contrarotate() sleep(5) move.stop() return analogVal
def setup(): # Set the GPIO modes to BCM Numbering GPIO.setmode(GPIO.BCM) GPIO.setup(BtnPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) ADC0834.setup()
def loop(): while True: analogVal = ADC0834.getResult() print('analog value = %d' % analogVal) led_val.ChangeDutyCycle(analogVal * 100 / 255) time.sleep(0.2)
def destroy(): LCD1602.clear() ADC0834.destroy() GPIO.cleanup()
def setupInput(): GPIO.setup(button, GPIO.IN) ADC0834.setup()
def init(): ADC0834.setup()
def setup(): GPIO.setmode(GPIO.BCM) ADC0834.setup() for i in ledPins: GPIO.setup(i, GPIO.OUT) GPIO.output(i, GPIO.HIGH)
# Put your device token here. To get the token, # sign up at https://cloud4rpi.io and create a device. DEVICE_TOKEN = 'M1vyY81aq3TQLbnFuepUFhA5' # Constants RELAY_PIN = 20 # Change these values depending on your requirements. DATA_SENDING_INTERVAL = 60 # secs DIAG_SENDING_INTERVAL = 650 # secs POLL_INTERVAL = 0.5 # 500 ms # Configure GPIO library GPIO.setmode(GPIO.BCM) GPIO.setup(RELAY_PIN, GPIO.OUT) ADC0834.setup() move = motor(13, 19, 26) # Handler for the button or switch variable def relay_control(value=None): GPIO.output(RELAY_PIN, value) return GPIO.input(RELAY_PIN) def getValue(): analogVal = ADC0834.getResult() if analogVal > 100: move.clockwise() sleep(5) move.stop()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import RPi.GPIO as GPIO import ADC0834 import time import math def init(): ADC0834.setup() def loop(): while True: analogVal = ADC0834.getResult() Vr = 5 * float(analogVal) / 255 Rt = 10000 * Vr / (5 - Vr) temp = 1/(((math.log(Rt / 10000)) / 3950) + (1 / (273.15+25))) Cel = temp - 273.15 Fah = Cel * 1.8 + 32 print ('Celsius: %.2f C Fahrenheit: %.2f F' % (Cel, Fah)) time.sleep(0.2) if __name__ == '__main__': init() try: loop() except KeyboardInterrupt: ADC0834.destroy()
def loop(): while True: analogVal = ADC0834.getResult() LedBarGraph(int(analogVal / 25))