Click here to Skip to main content
15,886,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Working on getting applescript (using serial port x) to read data from 2 arduino boards, in order to make changes to spotify and master volume through applescript. Currently the code works to a degree, it will read from one Ardunio (controlling play/pause) for a set duration, then swap to read from the other (controlling master volume) until the script is closed.

Ultimately I am trying to make the script alternate the serial port read between the two boards when an input occurs, then swap back to the other and so forth.

I am very new to this, but feel i'm pretty close to getting this working 100%, so any help would be greatly appreciated. Cheers!



set arduinoPort1 to "/dev/cu.usbserial-DA01LZ5L"
set arduinoPort2 to "/dev/cu.usbserial-DA01LL8E"
set arduino1 to serialport open arduinoPort1 bps rate 9600 data bits 8 parity 0 stop bits 1 handshake 0
if arduino1 is equal to -1 then
display dialog " could not open port (RFID KEEP CONNECT ERROR) "

end if
--port 1 connect and test

set arduino2 to serialport open arduinoPort2 bps rate 9600 data bits 8 parity 0 stop bits 1 handshake 0
if arduino2 is equal to -1 then
display dialog " could not open port (CAP REST CONNECT ERROR) "

--port 2 connect and test
else
repeat 60 times --seconds times

    set x to serialport read arduino1
    if x is equal to "A" then
        tell application "Spotify" to playpause
        delay 1
    end if 
end repeat
repeat
    set z to serialport read arduino2

    if z is equal to "G" then
        set volume output volume 10
        set volume output volume 5
        set volume output volume 0

        delay 0
    end if

    if z is equal to "FG" then
        set volume output volume 20
        set volume output volume 25
        set volume output volume 20
        delay 0
    end if

    if z is equal to "EFG" then
        set volume output volume 30
        set volume output volume 35
        set volume output volume 40
        delay 0
    end if

    if z is equal to "DEFG" then
        set volume output volume 50
        set volume output volume 55
        set volume output volume 60
        delay 0
    end if

    if z is equal to "CDEFG" then
        set volume output volume 70
        set volume output volume 75
        set volume output volume 80
        delay 0
    end if

    if z is equal to "BCDEFG" then
        set volume output volume 90
        set volume output volume 95
        set volume output volume 100
        delay 0


    end if
end repeat 

end if
end
end
Posted
Updated 25-Sep-15 22:59pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900