def get_pots(): """ Grab a reading from each of the pot pins and send it to a tuple to be read by the colour mixer """ r = Arduino.analogRead(pot_r_Pin) / 4 Arduino.delay(1) g = Arduino.analogRead(pot_g_Pin) / 4 Arduino.delay(1) b = Arduino.analogRead(pot_b_Pin) / 4 Arduino.delay(1) return r, g, b
def get_pots(): """ Grab a reading from each of the pot pins and send it to a tuple to be read by the colour mixer """ r = Arduino.analogRead(pot_r_Pin) / 4 Arduino.delay(1) g = Arduino.analogRead(pot_g_Pin) / 4 Arduino.delay(1) b = Arduino.analogRead(pot_b_Pin) / 4 Arduino.delay(1) return r, g, b
def GET(self): # x = [] while True: print "start to get the temperature info....." while True: sensorValue = Arduino.analogRead(analogPort) temperature = (sensorValue / 1023.) * powervoltage * 100 return temperature
def read_sensors(): """ Reads each of the Sharp sensors are returns a list of analog readings in order: front, right, left, rear """ reading = [] for i in [FrontBump, RightBump, LeftBump, RearBump]: reading.append(Arduino.analogRead(i)) Arduino.delay(1) return reading
def analogpin(pin_number): if request.method == 'GET': Arduino.pinMode(pin_number, Arduino.INPUT) data = { 'value' : Arduino.analogRead(pin_number) } resp = Response(json.dumps(data), status=200, mimetype='application/json') return resp else: Arduino.pinMode(pin_number, Arduino.OUTPUT) Arduino.analogWrite(pin_number, request.json['value']) resp = Response("", status=200, mimetype='application/json') return resp
def index(self,request): json = 0 data = 0 if request.args.get('json', '') == "1": json = 1 ser = Arduino() data = self.receiving(ser) sensorValue = Arduino.analogRead(analogPort) data= (sensorValue/1023.)*powervoltage*100 print "data = ", data html = self.showDemoHTML(data,json) return html
def receiving(self, ser): print "..recieving...." global last_received # data = 0.0 # buffer = '' # while True: sensorValue = Arduino.analogRead(analogPort) data= (sensorValue/1023.)*powervoltage*100 # buffer = buffer + ser.analogRead(analogPort) # data = temp_demo # if '\r\n' in buffer: # print ('Alas...') print ("temperature=",data) return data
def phase2(): av = 0 cnt = 0 outputpin = 0 while True: rawvoltage= Arduino.analogRead(outputpin) millivolts= float((rawvoltage/1024.0) * 5000.0) celsius = (millivolts)/10.0 tempf = (celsius * 9)/5 + 32 msgbox('degrees Celsius: {}\n degrees Fahrenheit: {}'.format(celsius, tempf)) lcd.setCursor(0, 0) lcd.printString(celsius) lcd.setCursor(0, 1) lcd.printString(tempf) time.sleep(10)
def phase2(): av = 0 cnt = 0 outputpin = 0 while True: rawvoltage = Arduino.analogRead(outputpin) millivolts = float((rawvoltage / 1024.0) * 5000.0) celsius = (millivolts) / 10.0 tempf = (celsius * 9) / 5 + 32 msgbox('degrees Celsius: {}\n degrees Fahrenheit: {}'.format( celsius, tempf)) lcd.setCursor(0, 0) lcd.printString(celsius) lcd.setCursor(0, 1) lcd.printString(tempf) time.sleep(10)
def getKey(): val = Arduino.analogRead(14) if val == 1023: return "NONE" elif val < 100: return "RIGHT" elif val < 150: return "UP" elif val < 330: return "DOWN" elif val < 510: return "LEFT" elif val < 750: return "SEL" else: return "KBD_FAULT"
def getKey(): # Function to Translate the analogRead values from the Keys to a Command val = Arduino.analogRead(14) if val == 1023: return "NONE" elif val < 100: return "RIGHT" elif val < 150: return "UP" elif val < 330: return "DOWN" elif val < 510: return "LEFT" elif val < 750: return "SEL" else: return "KBD_FAULT"
def showDemoHTML(self,data,json): ## reads an html file and does things with it ## there are better ways, but they are more complicated print "....showDemoHTML...." while True: sensorValue = Arduino.analogRead(analogPort) data= (sensorValue/1023.)*powervoltage*100 if json == 1: f = open(CURRENTDIR +"/json.html") html = f.read() html = html.replace("%Temperature%",str(data)) print html return html else: f = open(CURRENTDIR +"/temp.html") html = f.read() html = html.replace("%Temperature%",str(data)) print ".....demo....", data return html
def get_r(): r_val = Arduino.analogRead(pot_r_Pin) / 4 Arduino.delay(1) return r_val
#!/usr/bin/env python # LED with 560 Ohm resistor on Pin 10 to GND # Tony Goodhew - 10 May 2013 from nanpy import Arduino from nanpy import serial_manager serial_manager.connect('/dev/ttyACM0') # serial connection to Arduino from time import sleep import NGSIClient pins = [0, 1] for pin in pins: Arduino.pinMode(pin, Arduino.INPUT) while 4 < 5: temperaturesList = [] for pin in pins: print "Reading" value = Arduino.analogRead(pin) degreesC = (value * 0.004882814)*100 print "The voltage in pin " + str(pin) + " is " + str(degreesC) temperaturesList.append(degreesC) NGSIClient.createContext("Cuba", "CubaDani", NGSIClient.createMeasureArray("centrigrade", "temperature", temperaturesList)) sleep(5) print "Finished reading"
from nanpy import Arduino as A SENSOR_PIN_A0 = 14 BASELINE_TEMP = 20.0 # SETUP A.pinMode(2, A.OUTPUT) A.digitalWrite(2, A.LOW) A.pinMode(3, A.OUTPUT) A.digitalWrite(3, A.LOW) A.pinMode(4, A.OUTPUT) A.digitalWrite(4, A.LOW) # LOOP while True: sensorVal = A.analogRead(SENSOR_PIN_A0) voltage = (sensorVal / 1024.0) * 5.0 temperature = (voltage - 0.5) * 100 print("Sensor value: " + str(sensorVal) + ", Volts: " + str(voltage) +", Degrees C: " + str(temperature) + ".") # if the current temperature is lower than the baseline turn off all LEDs if temperature < BASELINE_TEMP: A.digitalWrite(2, A.LOW) A.digitalWrite(3, A.LOW) A.digitalWrite(4, A.LOW) # if the temperature rises 2-4 degrees, turn an LED on elif (temperature >= BASELINE_TEMP + 2 and temperature < BASELINE_TEMP + 4): A.digitalWrite(2, A.HIGH) A.digitalWrite(3, A.LOW) A.digitalWrite(4, A.LOW) # if the temperature rises 4-6 degrees, turn a second LED on
def rear_bump(): bump = Arduino.analogRead(RearBump) if bump > rearTrigger: return True else: return False
def left_bump(): bump = Arduino.analogRead(LeftBump) if bump > sideTrigger: return True else: return False
def right_bump(): bump = Arduino.analogRead(RightBump) if bump > sideTrigger: return True else: return False
def front_bump(): # check for bump, if bump detected return 1 bump = Arduino.analogRead(FrontBump) if bump > frontTrigger: return True else: return False
bright = bright + 8 if (bright > 200): # LED already full on at this point bright = 0 # Minimum power to LED Arduino.analogWrite(LED, bright) # Change PWM setting/brightness sleep(0.05) Arduino.digitalWrite(LED,Arduino.LOW) # Turn off LED print"Finished" print "now showing the temperature...." #stream = py.Stream(plotly_user_config['plotly_streaming_tokens'][0]) #stream.open() cnt = 0 try: while True: sensorValue = Arduino.analogRead(analogPort) temperature = (sensorValue/1023.)*powervoltage*100 # f = open('temp.txt','a') # f.write("room 1 " + str(datetime.datetime.now()) + " " + str(temperature) + "\n") print "room 1 ", datetime.datetime.now() ," ",temperature # write the data to plotly #stream.write({'x': datetime.datetime.now(), 'y': temperature}) tempC.append(temperature) drawnow(makeFig) # plt.plot(tempC) # mpld3.show() plt.pause(.00001) cnt=cnt+1 print "cnt= ", cnt if(cnt>50): tempC.pop(0)
def run(self): while True: temp = ((Arduino.analogRead(0) / 1024.0) * 5.0 - 0.5) * 100 lcd.printString("- %0.1f\xDFC" % temp, 6, 1) time.sleep(60)
def get_b(): b_val = Arduino.analogRead(pot_b_Pin) / 4 Arduino.delay(1) return b_val
def get_g(): g_val = Arduino.analogRead(pot_g_Pin) / 4 Arduino.delay(1) return g_val