On 03/01/15 19:19, Ted wrote:
Alan Thank you so much for the reply, attached is a screenshot of a 4.9M earthquake in Challis Idaho, about 150 miles north.
this is what I need the alarm for.

I am using Python 2.7? and Windows 7.

1.  Should I reply-all, or ok to you?  or either?

ReplyAll please, that way you get responses from everyone not just me.
And that's a very good thing, trust me! :-)

3. The data is coming from a serial port from an arduino........and I think this is a "string"

Yes, in Python2 it will be, in Python 3 it will be a bytestring
but you can ignore that for now! :-)

> I think I need to see it as an (int)?   But I don't know how.
> As you can see here is where I placed that.
> myData = int (arduinoSerialData.readline())

Thats exactly correct. int() converts the string to a number.

> I want to add an IF as you can see below, and this seems to work,
> but I am not sure I am seeing (int), because the numbers don't seem right.

Tell us what you see and what you expect.

The good news, is I do see the data in python, either a string or int???
The good news, is I can play the sound file as it is below.
Great, we'll look at it in more detail.


import serial #Import Serial Library
import time   # Slows the print
import winsound
arduinoSerialData = serial.Serial('com7', 9600) #Create Serial port object called arduinoSerialData # Don't change this.
myData = (arduinoSerialData.readline())

What happens if you print myData here?

while (1==1):

use

while True:

instead of the equality test.

>        myData = int (arduinoSerialData.readline())
>       if myData >33500:
           print(arduinoSerialData.readline())

Note this is printing the next thing from Arduino but not storing it anywhere.
You are throwing it away...

           time.sleep(1) #Slows to 1000ms
soundfile = "c:\Windows\Media\Alarms\Alarm.wav"#Song/Track to play(MUST be wav)

Windows paths can be troublesome due to the \ characters
which Python treats as special, you should prefix them with r
to tell Python to ignore the \

soundfile = r"c:\Windows\Media\Alarms\Alarm.wav"

Alternatively use Unix style / instead:

soundfile = "c:/Windows/Media/Alarms/Alarm.wav"


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to