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 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 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 loop(): while True: analogVal = ADC0834.getResult() print('analog value = %d' % analogVal) led_val.ChangeDutyCycle(analogVal * 100 / 255) time.sleep(0.2)
def loop(): while True: analogVal = ADC0834.getResult() LedBarGraph(int(analogVal / 25))