working python connection, though too much data right now, too slow connection
This commit is contained in:
parent
7fbc7230dc
commit
c1e6c76ca2
3 changed files with 58 additions and 4 deletions
|
@ -67,12 +67,18 @@ void setup() {
|
|||
delay(500);
|
||||
layout(tick);
|
||||
calcMaxTicks();
|
||||
|
||||
while(!Serial);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// print the string when a newline arrives:
|
||||
// print the string when a newline arrives:
|
||||
if (stringComplete) {
|
||||
setFromSerial( inputString );
|
||||
|
||||
// clear the string:
|
||||
inputString = "";
|
||||
stringComplete = false;
|
||||
}
|
||||
layout(tick++);
|
||||
if ( tick > maxticks ) tick = 0;
|
||||
|
|
|
@ -25,21 +25,27 @@ void setFromSerial (String inputString) {
|
|||
switch ( inputString.charAt(0) ) {
|
||||
case 'V':
|
||||
volume = inputString.substring(1).toInt();
|
||||
Serial.println("Setting volume to " + String(volume));
|
||||
break;
|
||||
case 'T':
|
||||
title = inputString.substring(1);
|
||||
Serial.println("Setting title to " + String(title));
|
||||
break;
|
||||
case 'A':
|
||||
artist = inputString.substring(1);
|
||||
Serial.println("Setting artist to " + String(artist));
|
||||
break;
|
||||
case 'a':
|
||||
album = inputString.substring(1);
|
||||
Serial.println("Setting album to " + String(album));
|
||||
break;
|
||||
case 'r':
|
||||
repeat = inputString.substring(1) != 0;
|
||||
Serial.println("Setting repeat to " + String(repeat));
|
||||
break;
|
||||
case 'z':
|
||||
shuffle = inputString.substring(1) != 0;
|
||||
Serial.println("Setting shuffle to " + String(shuffle));
|
||||
break;
|
||||
default:
|
||||
Serial.println(F("!Invalid line:"));
|
||||
|
@ -48,7 +54,4 @@ void setFromSerial (String inputString) {
|
|||
break;
|
||||
}
|
||||
calcMaxTicks();
|
||||
// clear the string:
|
||||
inputString = "";
|
||||
stringComplete = false;
|
||||
}
|
||||
|
|
45
ttycontrol.py
Executable file
45
ttycontrol.py
Executable file
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env python
|
||||
tty = '/dev/ttyACM1'
|
||||
baud = 9600
|
||||
|
||||
import serial
|
||||
import time
|
||||
|
||||
ser = serial.Serial(tty, baud)
|
||||
|
||||
# Setup
|
||||
print("Setup")
|
||||
print(ser)
|
||||
print("------")
|
||||
|
||||
ser.write("!Booya\n")
|
||||
ser.readline()
|
||||
|
||||
# Final Loop
|
||||
volume = 0
|
||||
title = "Blub"
|
||||
artist = "ee"
|
||||
album = "dd"
|
||||
repeat = True
|
||||
shuffle = True
|
||||
|
||||
|
||||
def output(string):
|
||||
ser.write(string+"\n")
|
||||
time.sleep(0.4)
|
||||
|
||||
def check_serial():
|
||||
if (ser.inWaiting()>0): #if incoming bytes are waiting to be read from the serial input buffer
|
||||
data_str = ser.read(ser.inWaiting()).decode('ascii') #read the bytes and convert from binary array to ASCII
|
||||
print(data_str)
|
||||
while True:
|
||||
volume = (volume + 1)
|
||||
output("V" + str(volume))
|
||||
output("T" + title)
|
||||
output("A" + artist)
|
||||
output("a" + album)
|
||||
output("r" + str(repeat))
|
||||
output("z" + str(shuffle))
|
||||
print("--- output ---")
|
||||
check_serial()
|
||||
print("--- output ---")
|
Loading…
Reference in a new issue