SlideShare a Scribd company logo
1 of 18
Download to read offline
PROGRAMMING DIGITAL TO ANALOG
PROGRAMMING ANALOG TO DIGITAL
Dr.M.Vidhyalakshmi
SRMIST,RMP
DAC
A digital-to-analog converter is a circuit which converts a binary input number into
an analog output.
LPC1768
LPC 1768
Mbed is rich in analog input/output capabilities.
Pins 15 to 20 can be analog input, while pin 18 is the only analog output.
API INTERFACE FOR MBED ANALOG OUTPUT
Creating Constant Output Voltages
/ Three values of DAC are output in turn on Pin 18. Read the output on a DVM.*/
#include "mbed.h"
AnalogOut Aout(p18); //create an analog output on pin 18
int main() {
while(1) {
Aout=0.25; // 0.25*3.3V = 0.825V
wait(2);
Aout=0.5; // 0.5*3.3V = 1.65V
wait(2);
Aout=0.75; // 0.75*3.3V = 2.475V
wait(2);
}
}
Trial DAC..Voltmeter
#include "mbed.h"
AnalogOut Aout(p18);
float i;
int main() {
while(1){
for (i=0;i<1;i=i+0.1){ // i is incremented in steps of 0.1
Aout=i;
wait(0.001); // wait 1 millisecond
}
}
}
Saw tooth waveform on DAC output.
#include "mbed.h"
AnalogOut Aout(p18);
float i;
int main() {
while(1){
for (i=0;i<1;i=i+0.1){ // i is incremented in steps
of 0.1
Aout=i;
wait(0.001); // wait 1 millisecond
}
}
}
/* Sine wave on DAC output. View on oscilloscope
#include "mbed.h"
AnalogOut Aout(p18);
float i;
int main() {
while(1) {
for (i=0;i<2;i=i+0.05) {
Aout=0.5+0.5*sin(i*3.14159); // Compute the sine
value, + half the range
wait(.001); // Controls the
sine wave period
}
API FOR PWM
PWM CONTROL TO DC MOTOR
*/
#include "mbed.h"
PwmOut PWM1(p21);
float i;
int main() {
PWM1.period(0.010); //set PWM period to 10 ms
while(1) {
for (i=0;i<1;i=i+0.01) {
PWM1=i; // update PWM duty cycle
wait(0.2);
}
}
}
/*Software generated PWM. 2 PWM values generated in turn, with full on and off included
for comparison.
#include "mbed.h"
DigitalOut motor(p6);
int i;
int main() {
while(1) {
motor = 0; //motor switched off for 5 secs
wait (5);
for (i=0;i<5000;i=i+1) { //5000 PWM cycles, low duty cycle
motor = 1;
wait_us(400); //output high for 400us
motor = 0;
wait_us(600); //output low for 600us
}
for (i=0;i<5000;i=i+1) { //5000 PWM cycles, high duty cycle
motor = 1;
wait_us(800); //output high for 800us
motor = 0;
wait_us(200); //output low for 200us
}
motor = 1; //motor switched fully on for 5 secs
wait (5);
}
}
/*Sets PWM source to fixed frequency and duty cycle. Observe
output on oscilloscope.
*/
#include "mbed.h"
PwmOut PWM1(p21); //create a PWM output called
PWM1 on pin 21
int main() {
PWM1.period(0.010); // set PWM period to 10
ms
PWM1=0.5; // set duty cycle to 50%
}
ADC
/* Uses analog input to control LED brightness, through DAC output
*/
#include "mbed.h"
AnalogOut Aout(p18); //defines analog output on Pin 18
AnalogIn Ain(p20) //defines analog input on Pin 20
int main() {
while(1) {
Aout=Ain; //transfer analog in value to analog out, both are
type float
}
}
/*Uses analog input (pOTENTIOMETER)to control PWM period.
#include "mbed.h"
PwmOut PWM1(p23);
AnalogIn Ain(p20);
int main() {
while(1){
PWM1.period(Ain/10+0.001); // set PWM
period
PWM1=0.5; // set duty
cycle
wait(0.5);
}
PWM SPEAKER
Frequencies of notes
#include "mbed.h"
PwmOut buzzer(p26);
//frequency array
float frequency[]={659,554,659,554,440,494,554,587,494,659,554,440};
float beat[]={1,1,1,1,1,0.5,0.5,1,1,1,1,2}; //beat array
int main() {
while (1) {
for (int i=0;i<=11;i++) {
buzzer.period(1/(2*frequency[i])); // set PWM period
buzzer=0.5; // set duty cycle
wait(0.4*beat[i]); // hold for beat period
}}}

More Related Content

Similar to PROGRAMMING ADC and DAC-mbed.pdf

04 adc (pic24, ds pic with dma)
04 adc (pic24, ds pic with dma)04 adc (pic24, ds pic with dma)
04 adc (pic24, ds pic with dma)antonio michua
 
Microcontroller_basics_lesson1_2019 (1).pptx
Microcontroller_basics_lesson1_2019 (1).pptxMicrocontroller_basics_lesson1_2019 (1).pptx
Microcontroller_basics_lesson1_2019 (1).pptxHebaEng
 
Analog To Digital Conversion (ADC) Programming in LPC2148
Analog To Digital Conversion (ADC) Programming in LPC2148Analog To Digital Conversion (ADC) Programming in LPC2148
Analog To Digital Conversion (ADC) Programming in LPC2148Omkar Rane
 
Arduino windows remote control
Arduino windows remote controlArduino windows remote control
Arduino windows remote controlVilayatAli5
 
Robotix Tutorial 9
Robotix Tutorial 9Robotix Tutorial 9
Robotix Tutorial 9ankuredkie
 
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdfJayanthi Kannan MK
 
Interfacing with Atmega 16
Interfacing with Atmega 16Interfacing with Atmega 16
Interfacing with Atmega 16Ramadan Ramadan
 
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IOT Academy
 
Pin diagram of 8085
Pin diagram of 8085Pin diagram of 8085
Pin diagram of 8085ShivamSood22
 
5 pin-diagram-of-8085-181203034237
5 pin-diagram-of-8085-1812030342375 pin-diagram-of-8085-181203034237
5 pin-diagram-of-8085-181203034237sunilkumar4879
 

Similar to PROGRAMMING ADC and DAC-mbed.pdf (20)

Arduino based applications part 1
Arduino based applications part 1Arduino based applications part 1
Arduino based applications part 1
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
8255
82558255
8255
 
04 adc (pic24, ds pic with dma)
04 adc (pic24, ds pic with dma)04 adc (pic24, ds pic with dma)
04 adc (pic24, ds pic with dma)
 
Presentation
PresentationPresentation
Presentation
 
Microcontroller_basics_lesson1_2019 (1).pptx
Microcontroller_basics_lesson1_2019 (1).pptxMicrocontroller_basics_lesson1_2019 (1).pptx
Microcontroller_basics_lesson1_2019 (1).pptx
 
Analog To Digital Conversion (ADC) Programming in LPC2148
Analog To Digital Conversion (ADC) Programming in LPC2148Analog To Digital Conversion (ADC) Programming in LPC2148
Analog To Digital Conversion (ADC) Programming in LPC2148
 
Arduino windows remote control
Arduino windows remote controlArduino windows remote control
Arduino windows remote control
 
Robotix Tutorial 9
Robotix Tutorial 9Robotix Tutorial 9
Robotix Tutorial 9
 
Arduino.pptx
Arduino.pptxArduino.pptx
Arduino.pptx
 
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
 
Interfacing with Atmega 16
Interfacing with Atmega 16Interfacing with Atmega 16
Interfacing with Atmega 16
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
EEE UNIT-2 PPT.pdf
EEE UNIT-2 PPT.pdfEEE UNIT-2 PPT.pdf
EEE UNIT-2 PPT.pdf
 
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programming
 
Pin diagram of 8085
Pin diagram of 8085Pin diagram of 8085
Pin diagram of 8085
 
5 pin-diagram-of-8085-181203034237
5 pin-diagram-of-8085-1812030342375 pin-diagram-of-8085-181203034237
5 pin-diagram-of-8085-181203034237
 
Arduino programming
Arduino programmingArduino programming
Arduino programming
 
Arduino Programming
Arduino ProgrammingArduino Programming
Arduino Programming
 

Recently uploaded

Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 

Recently uploaded (20)

Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 

PROGRAMMING ADC and DAC-mbed.pdf

  • 1. PROGRAMMING DIGITAL TO ANALOG PROGRAMMING ANALOG TO DIGITAL Dr.M.Vidhyalakshmi SRMIST,RMP
  • 2. DAC A digital-to-analog converter is a circuit which converts a binary input number into an analog output.
  • 4. LPC 1768 Mbed is rich in analog input/output capabilities. Pins 15 to 20 can be analog input, while pin 18 is the only analog output.
  • 5. API INTERFACE FOR MBED ANALOG OUTPUT
  • 6. Creating Constant Output Voltages / Three values of DAC are output in turn on Pin 18. Read the output on a DVM.*/ #include "mbed.h" AnalogOut Aout(p18); //create an analog output on pin 18 int main() { while(1) { Aout=0.25; // 0.25*3.3V = 0.825V wait(2); Aout=0.5; // 0.5*3.3V = 1.65V wait(2); Aout=0.75; // 0.75*3.3V = 2.475V wait(2); } }
  • 7. Trial DAC..Voltmeter #include "mbed.h" AnalogOut Aout(p18); float i; int main() { while(1){ for (i=0;i<1;i=i+0.1){ // i is incremented in steps of 0.1 Aout=i; wait(0.001); // wait 1 millisecond } } }
  • 8. Saw tooth waveform on DAC output. #include "mbed.h" AnalogOut Aout(p18); float i; int main() { while(1){ for (i=0;i<1;i=i+0.1){ // i is incremented in steps of 0.1 Aout=i; wait(0.001); // wait 1 millisecond } } }
  • 9. /* Sine wave on DAC output. View on oscilloscope #include "mbed.h" AnalogOut Aout(p18); float i; int main() { while(1) { for (i=0;i<2;i=i+0.05) { Aout=0.5+0.5*sin(i*3.14159); // Compute the sine value, + half the range wait(.001); // Controls the sine wave period }
  • 11.
  • 12. PWM CONTROL TO DC MOTOR */ #include "mbed.h" PwmOut PWM1(p21); float i; int main() { PWM1.period(0.010); //set PWM period to 10 ms while(1) { for (i=0;i<1;i=i+0.01) { PWM1=i; // update PWM duty cycle wait(0.2); } } }
  • 13. /*Software generated PWM. 2 PWM values generated in turn, with full on and off included for comparison. #include "mbed.h" DigitalOut motor(p6); int i; int main() { while(1) { motor = 0; //motor switched off for 5 secs wait (5); for (i=0;i<5000;i=i+1) { //5000 PWM cycles, low duty cycle motor = 1; wait_us(400); //output high for 400us motor = 0; wait_us(600); //output low for 600us } for (i=0;i<5000;i=i+1) { //5000 PWM cycles, high duty cycle motor = 1; wait_us(800); //output high for 800us motor = 0; wait_us(200); //output low for 200us } motor = 1; //motor switched fully on for 5 secs wait (5); } }
  • 14. /*Sets PWM source to fixed frequency and duty cycle. Observe output on oscilloscope. */ #include "mbed.h" PwmOut PWM1(p21); //create a PWM output called PWM1 on pin 21 int main() { PWM1.period(0.010); // set PWM period to 10 ms PWM1=0.5; // set duty cycle to 50% }
  • 15. ADC /* Uses analog input to control LED brightness, through DAC output */ #include "mbed.h" AnalogOut Aout(p18); //defines analog output on Pin 18 AnalogIn Ain(p20) //defines analog input on Pin 20 int main() { while(1) { Aout=Ain; //transfer analog in value to analog out, both are type float } }
  • 16. /*Uses analog input (pOTENTIOMETER)to control PWM period. #include "mbed.h" PwmOut PWM1(p23); AnalogIn Ain(p20); int main() { while(1){ PWM1.period(Ain/10+0.001); // set PWM period PWM1=0.5; // set duty cycle wait(0.5); }
  • 18. #include "mbed.h" PwmOut buzzer(p26); //frequency array float frequency[]={659,554,659,554,440,494,554,587,494,659,554,440}; float beat[]={1,1,1,1,1,0.5,0.5,1,1,1,1,2}; //beat array int main() { while (1) { for (int i=0;i<=11;i++) { buzzer.period(1/(2*frequency[i])); // set PWM period buzzer=0.5; // set duty cycle wait(0.4*beat[i]); // hold for beat period }}}