def main(): # Instantiate a Loudness sensor on analog pin A0, with an analog # reference voltage of 5.0 sensor = sensorObj.Loudness(0, 5.0) ## Exit handlers ## # This function stops python from printing a stacktrace when you hit control-C def SIGINTHandler(signum, frame): raise SystemExit # This function lets you run code on exit def exitHandler(): print "Exiting" sys.exit(0) # Register exit handlers atexit.register(exitHandler) signal.signal(signal.SIGINT, SIGINTHandler) # Every tenth of a second, sample the loudness and output it's # corresponding analog voltage. while (1): print "Detected loudness (volts): ", sensor.loudness() time.sleep(.1)
import HightTemp #Vibration sensor library import pyupm_ldt0028 as vibrationSensor #Acecelerometer sensor library import pyupm_mma7660 as accelerometerSensor ####################################################################### #VARIABLES ####################################################################### #Create the light sensor object using AIO pin 0 lightValue = grove.GroveLight(0) #Create the loudness sensor object using AIO pin 1 loudnessValue = loudnessSensor.Loudness(1, 3.0) #Create the temperature sensor object using AIO pin 2 #tempValue2 = mraa.Aio(2) #Create the vibration sensor object using AIO pin 3 vibrationValue = vibrationSensor.LDT0028(3) try: #Create the accelerometer sensor object using I2C 0 accelerometerValue = accelerometerSensor.MMA7660( accelerometerSensor.MMA7660_DEFAULT_I2C_BUS, accelerometerSensor.MMA7660_DEFAULT_I2C_ADDR) print(accelerometerSensor.MMA7660_DEFAULT_I2C_BUS) #Place device in standby accelerometerValue.setModeStandby()
# included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import time, sys, signal, atexit import pyupm_loudness as sensorObj # Instantiate a Loudness sensor on analog pin A0, with an analog # reference voltage of 5.0 sensor = sensorObj.Loudness(0, 5.0) ## Exit handlers ## # This function stops python from printing a stacktrace when you hit control-C def SIGINTHandler(signum, frame): raise SystemExit # This function lets you run code on exit def exitHandler(): print "Exiting" sys.exit(0) # Register exit handlers