Finished all tasks of the workshop, just need to do the final task where the main decided which functions to run

Dependencies:   mbed C12832

Files at this revision

API Documentation at this revision

Comitter:
kwstasfane1
Date:
Tue Nov 17 15:26:43 2020 +0000
Commit message:
Finished all tasks, all i really need to do is to put them together 6.Task4)

Changed in this revision

C12832.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 6d566e6d9aa7 C12832.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832.lib	Tue Nov 17 15:26:43 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/askksa12543/code/C12832/#990d5eec2ef6
diff -r 000000000000 -r 6d566e6d9aa7 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 17 15:26:43 2020 +0000
@@ -0,0 +1,165 @@
+#include "mbed.h"
+
+#include "C12832.h" //LCD display library
+
+Serial pc(USBTX,USBRX); //serial port to communicate with pc
+//PwmOut PWM1(p21); //used for the pwm setup
+//PwmOut led (LED1);
+
+//task5 testing and orages song
+DigitalIn fire(p14);
+PwmOut spkr(p26); //pwm directed to pin26 speaker
+
+
+//extra song, Star WARS
+float frequency [] = {175,175,175,233,349,311,294,523,932,698,622,587,523,932,698,622,587,622,523};
+float beat [] = {21,21,21,128,64,21,21,21,128,64,21,21,21,128,64,21,21,21,128};
+int length = sizeof(beat)/sizeof(beat[0]); //to get the length of the array //not use it in a main()
+
+//oranges and lemons song
+//float frequency [] = {659, 554, 659, 554, 550, 494, 554, 587, 494, 659, 554, 440}; //frequency array
+//float beat[] = {1, 1, 1, 1, 1, 0.5, 0.5, 1, 1, 1, 1, 2}; //beat array
+
+C12832 lcd(p5, p7, p6, p8, p11); //define lcd pins
+
+char getChar();
+float getFloat();
+//void basicPWM();
+//void ledPwm(float);
+
+
+int main()
+{
+    //Task2.1
+    //pc.printf("Workshop 6\n\r"); //the \n\r gives new line and cariage return carriage return
+    
+    //Task2.2
+    /*char c; //this holds the data pc sends
+    while(1)
+    {
+        c = pc.getc(); //gets character from input stream
+        lcd.cls();
+        lcd.locate(10,10);
+        lcd.printf("%c", c); //display the character
+    }*/
+    
+    //Task2.3
+    /*while(1)
+    {
+        float num = getFloat(); //read the formated data as printf prints it
+        lcd.cls();
+        lcd.locate(10,10);
+        lcd.printf("%4.3f",num); //4.3 decimal accuracy
+    }*/
+    //basicPWM();
+    
+    //Task4
+    /*float brightness = 0.0;
+    char c;
+    
+    while(1)
+    {
+        pc.printf("Control of LED dimmer by host terminal \n\r");
+        pc.printf("Press 'u'= brighter, 'd'=dimmer\n\r");
+        pc.printf("%c %1.3f \n \r", c, brightness);
+        
+        c = pc.getc();
+
+        if(brightness > 0.2) //set 0.2 upper limit
+        {
+            brightness = 0.2;
+        }
+        else if(brightness < 0.0) //set 0.0 lower limit
+        {
+            brightness = 0.0;
+        }
+        else
+        {
+            if(c == 'u')
+            {
+                brightness = brightness + 0.0001; //brightness increase
+            }
+            if(c == 'd')
+            {
+                brightness = brightness - 0.0001; //brightness decrease
+            }
+        }
+        
+        ledPwm(brightness);
+        
+        
+    }*/
+    
+    //Task 5, speaker test
+    /*while(1)
+    {
+        for(float i= 2000.0; i<10000.0; i+=100)
+        {
+            spkr.period(1.0/i); //frequency sweep from 2Khz to 10KHz, period=1/f 
+            spkr = 0.5; //50% duty cycle
+            wait(0.1);
+        }
+        
+        spkr = 0.0; //nute speaker
+        while(!fire){}
+    }*/
+    
+    //task5, speaker orange song
+    /*while(1)
+    {
+        for(int i=0; i<= 11; i++)
+        {
+            spkr.period(1.0/frequency[i]); //variable frequency dewpending on song notes
+            spkr = 0.5; //50% duty cycle
+            wait(0.5*beat[i]); //hold for beat period
+        }
+        
+        spkr = 0.0; //mute speaker
+        while(!fire){}
+    }*/
+    
+    
+    while(1)
+    {
+        for(int i=0; i<length; i++)
+        {
+            spkr.period(1.0/frequency[i]); //convert frequency to time and use it as period
+            spkr = 0.5; //50% duty cycle
+            wait(0.5*beat[i]*0.02); //0.02 is used to adjust the speed of the music
+        }
+        
+        spkr = 0.0; //mute the speaker
+        while(!fire){}
+    }
+    
+    //return 0;
+    
+    
+}
+
+/*void ledPwm(float brightness) //for the led online adjusting
+{
+    led.period(0.001); //100Hz=T
+    led = brightness;
+}*/
+
+/*void basicPWM() //for the PWM online adjusting 
+{
+    //create a PWM signal to see on the osciloscope (Pulse = 100Hz and DT= 50%
+    PWM1.period(getFloat()); //set the PWM period to 10ms, used to configure period remotel as well
+    PWM1 = getFloat(); //set the duty cycle to 50% (from 0.0 to 1.0 0% to 100%)
+}*/
+
+float getFloat()
+{
+    float num;
+    pc.scanf("%f", &num);
+    return (num);
+}
+
+char getChar()
+{
+    char c;
+    pc.getc();
+    return c;
+}
diff -r 000000000000 -r 6d566e6d9aa7 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Nov 17 15:26:43 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file