voici

Fork of m3pi by Samir Bouaziz

Files at this revision

API Documentation at this revision

Comitter:
Maximousse
Date:
Thu May 03 12:06:02 2018 +0000
Parent:
9:f65c5aa1775c
Commit message:
test2

Changed in this revision

m3pi.cpp Show annotated file Show diff for this revision Revisions of this file
m3pi.h Show annotated file Show diff for this revision Revisions of this file
diff -r f65c5aa1775c -r a12166fc8c19 m3pi.cpp
--- a/m3pi.cpp	Mon Nov 23 23:22:28 2015 +0000
+++ b/m3pi.cpp	Thu May 03 12:06:02 2018 +0000
@@ -182,6 +182,19 @@
     return(0);
 }
 
+
+void m3pi::play (char* music, int length) {
+    // The default 3pi serial slave program
+    // will not accept music strings longer than 100.
+    if (length > 100)
+        length = 100;
+    _ser.putc(DO_PLAY);
+    _ser.putc(length);
+    for (int i = 0 ; i < length ; i++) {
+        _ser.putc(music[i]); 
+    }
+}
+
 int m3pi::_putc (int c) {
     _ser.putc(DO_PRINT);  
     _ser.putc(0x1);       
diff -r f65c5aa1775c -r a12166fc8c19 m3pi.h
--- a/m3pi.h	Mon Nov 23 23:22:28 2015 +0000
+++ b/m3pi.h	Thu May 03 12:06:02 2018 +0000
@@ -223,6 +223,16 @@
      * @param int The character to send to the 3pi
      */
     int print(char* text, int length);
+    
+    /** Send a string buffer to the 3pi serial interface for
+     * playing music. See here for details about the string's 
+     * format:
+     *   http://www.pololu.com/docs/0J18/3
+     * @param music A pointer to a char array
+     * @param length The length of the music string
+     */
+    void play(char* music, int length);
+ 
 
 #ifdef MBED_RPC
     virtual const struct rpc_method *get_rpc_methods();