# in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # This is tested on the CircuitPlayground Express import adafruit_rtttl import digitalio import board enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE) enable.switch_to_output(value=True) adafruit_rtttl.play(board.SPEAKER, "itchy:d=8,o=6,b=160:c,a5,4p,c,a,4p,c,a5,c,a5," + \ "c,a,4p,p,c,d,e,p,e,f,g,4p,d,c,4d,f,4a#,4a,2c7") adafruit_rtttl.play(board.SPEAKER, "Phantom:d=4,o=5,b=140:c,f,c,d#.,8c#,2c#,a#4," + \ "d#,8a#4,2c,c,f,c,d#.,8c#,2c#,a#4,d#.,8a#4,2c,p,c,f,g#,c.6,8a#,2a#,a#,d#.6,8a#," + \ "2c6,p,c6,2f.6,8d#6,8c#6,8c6,8a#,8g#,8g,8f,2e,c#,c#.,8c,2c")
song = "d=4,o=4,b=160:8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5,8f#5,8e5,8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5" songConfig = song.split(":")[0] songNotes = song.split(":")[1].split(",") for i in range(0, len(songNotes) - 1): #TurnOffPixels() currentNote = songNotes[i] redValue = random.randint(0,255) greenValue = random.randint(0,255) blueValue = random.randint(0,255) #print(currentNote) if "a" in currentNote: pixels[1] = (redValue, greenValue, blueValue) elif "b" in currentNote: pixels[2] = (redValue, greenValue, blueValue) elif "c" in currentNote: pixels[3] = (redValue, greenValue, blueValue) elif "d" in currentNote: pixels[4] = (redValue, greenValue, blueValue) elif "e" in currentNote: pixels[5] = (redValue, greenValue, blueValue) elif "f" in currentNote: pixels[6] = (redValue, greenValue, blueValue) elif "g" in currentNote: pixels[7] = (redValue, greenValue, blueValue) else: pixels[8] = (redValue, greenValue, blueValue) pixels.show() adafruit_rtttl.play(board.A0, "Note:" + songConfig + ":" + currentNote) TurnOffPixels()