![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Part One of my Project Course. Implementation of simple I/O and a custom defined protocol over UDP/IP.
Dependencies: C12832 LM75B mbed EthernetInterface mbed-rtos
buzzer_music.cpp@1:b5c534165dfe, 2018-03-14 (annotated)
- Committer:
- bertgereels
- Date:
- Wed Mar 14 07:59:21 2018 +0000
- Revision:
- 1:b5c534165dfe
- Parent:
- 0:88d3b9015f7c
- Child:
- 2:6bfe732ba6bc
Added slave state machine.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bertgereels | 0:88d3b9015f7c | 1 | #include "buzzer_music.h" |
bertgereels | 1:b5c534165dfe | 2 | #include <string.h> |
bertgereels | 0:88d3b9015f7c | 3 | |
bertgereels | 0:88d3b9015f7c | 4 | namespace ProjectOne{ |
bertgereels | 0:88d3b9015f7c | 5 | |
bertgereels | 0:88d3b9015f7c | 6 | const int BuzzerMusic::frequencies[] = {110,110,110,98,130,110,98,130,110,165,165,165,175,130,104,98,130}; |
bertgereels | 0:88d3b9015f7c | 7 | const int BuzzerMusic::lengths[] = {480,480,480,360,120,480,360,120,960,480,480,480,360,120,480,360,120}; |
bertgereels | 0:88d3b9015f7c | 8 | const int BuzzerMusic::delays[] = {100,100,100,75,100,100,75,100,100,100,100,100,75,100,100,75,100}; |
bertgereels | 0:88d3b9015f7c | 9 | |
bertgereels | 0:88d3b9015f7c | 10 | BuzzerMusic::BuzzerMusic(PinName speakerPin) : speaker(speakerPin){ |
bertgereels | 0:88d3b9015f7c | 11 | |
bertgereels | 0:88d3b9015f7c | 12 | } |
bertgereels | 0:88d3b9015f7c | 13 | |
bertgereels | 1:b5c534165dfe | 14 | void BuzzerMusic::playMusic(std::string indexes){ |
bertgereels | 1:b5c534165dfe | 15 | char *command_info[2]; |
bertgereels | 1:b5c534165dfe | 16 | int i = 0; |
bertgereels | 1:b5c534165dfe | 17 | char *p = strtok ((char *)indexes.c_str(), "-"); |
bertgereels | 1:b5c534165dfe | 18 | while (p != NULL) |
bertgereels | 1:b5c534165dfe | 19 | { |
bertgereels | 1:b5c534165dfe | 20 | command_info[i++] = p; |
bertgereels | 1:b5c534165dfe | 21 | p = strtok (NULL, "-"); |
bertgereels | 0:88d3b9015f7c | 22 | } |
bertgereels | 1:b5c534165dfe | 23 | int x = atoi(command_info[0]); |
bertgereels | 1:b5c534165dfe | 24 | int y = atoi(command_info[1]); |
bertgereels | 1:b5c534165dfe | 25 | |
bertgereels | 1:b5c534165dfe | 26 | if(x >= 0 && y <= 17){ |
bertgereels | 1:b5c534165dfe | 27 | for(int i = x; i < y; i ++){ |
bertgereels | 1:b5c534165dfe | 28 | speaker = 0.5; |
bertgereels | 1:b5c534165dfe | 29 | speaker.period(1.0/frequencies[i]); |
bertgereels | 1:b5c534165dfe | 30 | wait((float)lengths[i]/1000); |
bertgereels | 1:b5c534165dfe | 31 | speaker = 0.0; |
bertgereels | 1:b5c534165dfe | 32 | wait((float)delays[i]/1000); |
bertgereels | 1:b5c534165dfe | 33 | } |
bertgereels | 1:b5c534165dfe | 34 | printf("Played Music\r\n"); |
bertgereels | 1:b5c534165dfe | 35 | }else{ |
bertgereels | 1:b5c534165dfe | 36 | printf("Indexes not valid!\r\n"); |
bertgereels | 1:b5c534165dfe | 37 | } |
bertgereels | 1:b5c534165dfe | 38 | |
bertgereels | 0:88d3b9015f7c | 39 | } |
bertgereels | 0:88d3b9015f7c | 40 | |
bertgereels | 0:88d3b9015f7c | 41 | } |
bertgereels | 0:88d3b9015f7c | 42 |