/** * PWM tone library demo * * Author: Jan Dvořák z Vozerovic * E-mail: dvorkaman@gmail.com * Web: dvorkaman.asp2.cz * Created: 2014 */ /* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // Includes #include "stdio.h" #include "libSystem.h" #include "libSystemTime.h" #include "libPWM.c" #include "libPWMTone.c" // Flintstones main theme #define NOTES_COUNT 100 char* nokiaString = "4#g2 4#c2 8- 4#c3 8#a2 4#g2 4#c2 8- 4#g2 8#f2 8f2 8f2 8#f2 8#g2 4#c2 4#d2 2f2 2- 4#g2 4#c2 8- 4#c3 8#a2 4#g2 4#c2 8- 4#g2 8#f2 8f2 8f2 8#f2 8#g2 4#c2 4#d2 2#c2"; uint16_t notes[NOTES_COUNT]; uint16_t durations[NOTES_COUNT]; /** * Main method */ int main(void) { libPWMpin pwmPin; libPWMtone tone; // init system_initialize(3); systemTime_initialize(); pwm_initializeTimer3Remap(); pwm_initializePin(&pwmPin, TIM3, 1); pwmTone_melodyInitializeDurations(&tone, &pwmPin, NOTES_COUNT, notes, durations); // load melody pwmTone_loadMelodyFromNokiaString(&tone, nokiaString, NOTES_COUNT, 200); // main loop while (1) { pwmTone_melodyPlay(&tone); // play only once } }