1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| import processing.serial.*; import ddf.minim.*; color circleColor = color(255); Minim minim; AudioPlayer player; Serial arduino; float circleSize; String currentSong = "Please Select a Track";
void setup() { size(600, 600); surface.setTitle("Music Player"); arduino = new Serial(this, "COM4", 9600); minim = new Minim(this); player = minim.loadFile("music1.mp3"); }
void draw() { while (arduino.available() > 0) { String data = arduino.readStringUntil('\n'); if (data != null && data.trim().length() > 0) { try { long val = Long.parseLong(data.trim(), 16); changeSong(val); } catch (NumberFormatException e) { println("Error parsing hex value: " + data.trim()); } } }
background(255); textAlign(CENTER); textSize(32); fill(0); text(currentSong, width / 2, height / 2 - 150);
circleSize = map(player.mix.level(), 0, 1, 50, 500); fill(circleColor); ellipse(width / 2, height / 2, circleSize, circleSize); }
void changeSong(long key) { if (key == 0xFF30CF) { player.close(); player = minim.loadFile("music1.mp3"); player.play(); circleColor = color(135, 206, 250); currentSong = "Currently Playing\nCastle in the Sky"; } else if (key == 0xFF18E7) { player.close(); player = minim.loadFile("music2.mp3"); player.play(); circleColor = color(0, 0, 139); currentSong = "Currently Playing\nThe Rain"; } else if (key == 0xFF7A85) { player.close(); player = minim.loadFile("music3.mp3"); player.play(); circleColor = color(255, 255, 224); currentSong = "Currently Playing\nMerry Go Round"; } else if (key == 0xFFA25D) { player.close(); circleColor = color(255, 255, 255); currentSong = "Please Select a Track"; } }
|