V1 MP3 en liaison série

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
vermaelen
Date:
Sat May 14 07:45:22 2022 +0000
Commit message:
V1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mp3.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 8dd35bae21bb main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat May 14 07:45:22 2022 +0000
@@ -0,0 +1,163 @@
+#include "mbed.h"
+#include "mp3.h"
+//Serial mp3(PTE22,PTE23);
+Serial mp3(D14,D15);
+DigitalOut myled(LED1);
+int choix;
+int volume=16;
+
+int main()
+{
+    while(1) {
+        printf("1-play/pause 2-stop 3-next 4-previous\n\r");
+        printf("faites votre choix :");
+        scanf("%d",&choix);
+        printf("%d\n\n\n\r",choix);
+        switch(choix) {
+            case 1:
+                playpause();
+                break;
+            case 2:
+                stop();
+                break;
+            case 3:
+                next();
+                break;
+            case 4:
+                previous();
+                break;
+            case 9:
+                up();
+                break;
+            case 6:
+                down();
+                break;
+            case 5:
+                number(5);
+                break;
+            case 7:
+                number(7);
+                break;
+        }
+        myled.write(!myled.read());
+
+    }
+}
+
+void playpause()
+{
+    mp3.putc(0x7E);
+    wait_ms(5);
+    mp3.putc(0x03);
+    wait_ms(5);
+    mp3.putc(0xAA);
+    wait_ms(5);
+    mp3.putc(0xAD);
+    wait_ms(5);
+    mp3.putc(0xEF);
+    wait_ms(5);
+}
+
+void stop()
+{
+    mp3.putc(0x7E);
+    wait_ms(5);
+    mp3.putc(0x03);
+    wait_ms(5);
+    mp3.putc(0xAB);
+    wait_ms(5);
+    mp3.putc(0xAE);
+    wait_ms(5);
+    mp3.putc(0xEF);
+    wait_ms(5);
+}
+
+void next()
+{
+    mp3.putc(0x7E);
+    wait_ms(5);
+    mp3.putc(0x03);
+    wait_ms(5);
+    mp3.putc(0xAC);
+    wait_ms(5);
+    mp3.putc(0xAF);
+    wait_ms(5);
+    mp3.putc(0xEF);
+    wait_ms(5);
+}
+
+void previous()
+{
+    mp3.putc(0x7E);
+    wait_ms(5);
+    mp3.putc(0x03);
+    wait_ms(5);
+    mp3.putc(0xAD);
+    wait_ms(5);
+    mp3.putc(0xB0);
+    wait_ms(5);
+    mp3.putc(0xEF);
+    wait_ms(5);
+}
+void up()
+{
+    int sum;
+    volume=volume+1;
+    if(volume>31)volume=31;
+    sum=178+volume;
+    printf("volume=%x sum=%x\n\r",(char)volume,(char)sum);
+    mp3.putc(0x7E);
+    wait_ms(5);
+    mp3.putc(0x04);
+    wait_ms(5);
+    mp3.putc(0xAE);
+    wait_ms(5);
+    mp3.putc((char)volume);
+    wait_ms(5);
+    mp3.putc((char)sum);
+    wait_ms(5);
+    mp3.putc(0xEF);
+    wait_ms(5);
+}
+void down()
+{
+    int sum;
+    volume=volume-1;
+
+    if(volume<0)volume=0;
+
+    sum=volume+178;
+    printf("volume=%x sum=%x\n\r",(char)volume,(char)sum);
+    mp3.putc(0x7E);
+    wait_ms(5);
+    mp3.putc(0x04);
+    wait_ms(5);
+    mp3.putc(0xAE);
+    wait_ms(5);
+    mp3.putc((char)volume);
+    wait_ms(5);
+    mp3.putc((char)sum);
+    wait_ms(5);
+    mp3.putc(0xEF);
+    wait_ms(5);
+}
+
+void number(int nb)
+{
+    int sum=nb+5+0+0xA2;
+    printf("Ok, jouons la piste %d\n\r",nb);
+    mp3.putc(0x7E);
+    wait_ms(5);
+    mp3.putc(0x05);
+    wait_ms(5);
+    mp3.putc(0xA2);
+    wait_ms(5);
+    mp3.putc(0x00);
+    wait_ms(5);
+    mp3.putc((char)nb);
+    wait_ms(5);
+    mp3.putc((char)sum);
+    wait_ms(5);
+    mp3.putc(0xEF);
+    wait_ms(5);
+}
\ No newline at end of file
diff -r 000000000000 -r 8dd35bae21bb mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat May 14 07:45:22 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file
diff -r 000000000000 -r 8dd35bae21bb mp3.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3.h	Sat May 14 07:45:22 2022 +0000
@@ -0,0 +1,7 @@
+void playpause();
+void stop();
+void next();
+void previous();
+void up();
+void down();
+void number(int);
\ No newline at end of file