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);
|
delay(500);
|
||||||
layout(tick);
|
layout(tick);
|
||||||
calcMaxTicks();
|
calcMaxTicks();
|
||||||
|
|
||||||
|
while(!Serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// print the string when a newline arrives:
|
// print the string when a newline arrives:
|
||||||
if (stringComplete) {
|
if (stringComplete) {
|
||||||
setFromSerial( inputString );
|
setFromSerial( inputString );
|
||||||
|
|
||||||
|
// clear the string:
|
||||||
|
inputString = "";
|
||||||
|
stringComplete = false;
|
||||||
}
|
}
|
||||||
layout(tick++);
|
layout(tick++);
|
||||||
if ( tick > maxticks ) tick = 0;
|
if ( tick > maxticks ) tick = 0;
|
||||||
|
|
|
@ -25,21 +25,27 @@ void setFromSerial (String inputString) {
|
||||||
switch ( inputString.charAt(0) ) {
|
switch ( inputString.charAt(0) ) {
|
||||||
case 'V':
|
case 'V':
|
||||||
volume = inputString.substring(1).toInt();
|
volume = inputString.substring(1).toInt();
|
||||||
|
Serial.println("Setting volume to " + String(volume));
|
||||||
break;
|
break;
|
||||||
case 'T':
|
case 'T':
|
||||||
title = inputString.substring(1);
|
title = inputString.substring(1);
|
||||||
|
Serial.println("Setting title to " + String(title));
|
||||||
break;
|
break;
|
||||||
case 'A':
|
case 'A':
|
||||||
artist = inputString.substring(1);
|
artist = inputString.substring(1);
|
||||||
|
Serial.println("Setting artist to " + String(artist));
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
album = inputString.substring(1);
|
album = inputString.substring(1);
|
||||||
|
Serial.println("Setting album to " + String(album));
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
repeat = inputString.substring(1) != 0;
|
repeat = inputString.substring(1) != 0;
|
||||||
|
Serial.println("Setting repeat to " + String(repeat));
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
shuffle = inputString.substring(1) != 0;
|
shuffle = inputString.substring(1) != 0;
|
||||||
|
Serial.println("Setting shuffle to " + String(shuffle));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Serial.println(F("!Invalid line:"));
|
Serial.println(F("!Invalid line:"));
|
||||||
|
@ -48,7 +54,4 @@ void setFromSerial (String inputString) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
calcMaxTicks();
|
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