3872 Project GT

Dependencies:   MPR121 mbed Servo

Files at this revision

API Documentation at this revision

Comitter:
chenchen2020
Date:
Sun Oct 25 20:53:46 2020 +0000
Commit message:
V1

Changed in this revision

MPR121.lib Show annotated file Show diff for this revision Revisions of this file
Servo.lib Show annotated file Show diff for this revision Revisions of this file
SongPlayer.h 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 fb39f3e8d0d1 MPR121.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MPR121.lib	Sun Oct 25 20:53:46 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/electromotivated/code/MPR121/#f0e656f25701
diff -r 000000000000 -r fb39f3e8d0d1 Servo.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Sun Oct 25 20:53:46 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/simon/code/Servo/#36b69a7ced07
diff -r 000000000000 -r fb39f3e8d0d1 SongPlayer.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SongPlayer.h	Sun Oct 25 20:53:46 2020 +0000
@@ -0,0 +1,41 @@
+#include "mbed.h"
+// new class to play a note on Speaker based on PwmOut class
+class SongPlayer
+{
+public:
+    SongPlayer(PinName pin) : _pin(pin) {
+// _pin(pin) means pass pin to the constructor
+    }
+// class method to play a note based on PwmOut class
+    void PlaySong(float frequency[], float duration[], float volume=1.0) {
+        vol = volume;
+        notecount = 0;
+        _pin.period(1.0/frequency[notecount]);
+        _pin = volume/2.0;
+        noteduration.attach(this,&SongPlayer::nextnote, duration[notecount]);
+        // setup timer to interrupt for next note to play
+        frequencyptr = frequency;
+        durationptr = duration;
+        //returns after first note starts to play
+    }
+    void nextnote();
+private:
+    Timeout noteduration;
+    PwmOut _pin;
+    int notecount;
+    float vol;
+    float * frequencyptr;
+    float * durationptr;
+};
+//Interrupt Routine to play next note
+void SongPlayer::nextnote()
+{
+    _pin = 0.0;
+    notecount++; //setup next note in song
+    if (durationptr[notecount]!=0.0) {
+        _pin.period(1.0/frequencyptr[notecount]);
+        noteduration.attach(this,&SongPlayer::nextnote, durationptr[notecount]);
+        _pin = vol/2.0;
+    } else
+        _pin = 0.0; //turn off on last note
+}
\ No newline at end of file
diff -r 000000000000 -r fb39f3e8d0d1 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Oct 25 20:53:46 2020 +0000
@@ -0,0 +1,100 @@
+#include "mbed.h"
+#include "Servo.h"
+#include <mpr121.h>
+#include "SongPlayer.h"
+
+#define max_note 40
+#define max_timer_seconds 20
+#define A2 110.0
+#define B2 123.0
+#define C3 131.0
+#define D3 185.0
+#define E3 165.0
+#define F3 174.614
+#define G3 195.998
+#define G_# 207.652
+
+uint8_t     mode = 0;
+DigitalIn   record_mode(p14);
+DigitalIn   play_back_mode(p16);
+DigitalIn   play_live_mode(p15);
+DigitalIn   STOP(p17);
+DigitalOut  GreenLED(p18);
+DigitalOut  IndicatorLED(p19);
+DigitalIn   RESET(p20);
+I2C         i2c(p9, p10);
+
+Mpr121      mpr121(&i2c, Mpr121::ADD_VSS);
+InterruptIn interrupt(p30);
+Servo       skull_jaw(p26);
+Servo       skull_base(p25);
+Servo       spare_servo(p24);
+PwmOut      RED_LED(p23);
+PwmOut      Blue_LED(p22);
+SongPlayer  mySpeaker(p21);
+
+bool expired; //Timer expiration
+
+//Instantiate Skull Object
+
+class skull{
+  public:
+      char memory[40];
+      void openJaw(float angle);
+      void turn_table(float angle);
+      void play_tune(float tune);
+      void record_memory();
+      void erase_memory();
+      void append_memory();
+};
+
+int main() {
+    while(1) {
+        if(record_mode == 1){
+            mode = 1;   
+        }
+        if(play_back_mode == 1){
+            mode = 2;
+        }
+        if(play_live_mode == 1){
+            mode = 3;
+        }
+        if(STOP == 1){
+            mode = 4;
+        }
+        switch(mode){
+            case 1:
+                //Record Mode
+            break;
+            case 2:
+                //Play_back_mode
+            break;
+            case 3:
+                //play_live_mode
+            break;
+            case 4:
+                //Stop
+            break;
+            case 5:
+                //Reset
+            break;
+        }
+    }
+}
+
+void fallInterrupt() {
+    //int key_code=0;
+    //int i=0;
+    if(mode == 1 && !expired){
+        //write the recorded stuff here
+    } //recording mode
+    
+    if(mode == 2){
+        uint16_t value=mpr121.read(0x00);
+        value +=mpr121.read(0x01)<<8;
+        float note[] = {value + 110};
+        float duration[] = {0.24};
+        if(note[0]>110){
+            mySpeaker.PlaySong(note, duration);}
+        }
+}
diff -r 000000000000 -r fb39f3e8d0d1 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Oct 25 20:53:46 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file