
ECE 4180 Final Project
Revision 3:660252b9fa29, committed 2018-12-12
- Comitter:
- amitchell41
- Date:
- Wed Dec 12 17:11:24 2018 +0000
- Parent:
- 2:59677142d3dd
- Commit message:
- Final version
Changed in this revision
Speaker.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 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Speaker.h Wed Dec 12 17:11:24 2018 +0000 @@ -0,0 +1,19 @@ +#include "mbed.h" +// a new class to play a note on Speaker based on PwmOut class +class Speaker +{ +public: + Speaker(PinName pin) : _pin(pin) { +// _pin(pin) means pass pin to the Speaker Constructor + } +// class method to play a note based on PwmOut class + void PlayNote(float frequency, float duration, float volume) { + _pin.period(1.0/frequency); + _pin = volume/2.0; + wait(duration); + _pin = 0.0; + } + +private: + PwmOut _pin; +}; \ No newline at end of file
--- a/main.cpp Tue Dec 11 00:56:05 2018 +0000 +++ b/main.cpp Wed Dec 12 17:11:24 2018 +0000 @@ -2,45 +2,45 @@ #include "Servo.h" #include "MMA8452.h" #include "PinDetect.h" - - Serial pc(USBTX,USBRX); - DigitalOut myLed(LED1); - PinDetect pb1(p20); - DigitalOut Comm(p11); //If master - //DigitalIn Comm(p11); //If slave +Serial pc(USBTX,USBRX); +DigitalOut myLed(LED1); +PinDetect pb1(p26); + + - DigitalOut Red4(p5); - DigitalOut Red3(p6); - DigitalOut Yel2(p7); - DigitalOut Grn1(p8); +DigitalOut Red4(p5); +DigitalOut Red3(p6); +DigitalOut Yel2(p7); +DigitalOut Grn1(p8); + - Servo _base(p21); - Servo _shoulder(p22); - Servo _elbow(p23); - Servo _sword(p24); +Servo _base(p21); +Servo _shoulder(p22); +Servo _elbow(p23); +Servo _sword(p24); + void countdown(){ - Comm = 1; Red4 = 1; - wait(1); + wait(.75); Red4 = 0; Red3 = 1; - wait(1); + wait(.75); Red3 = 0; Yel2 = 1; - wait(1); + wait(.75); Red4 = 1; Red3 = 1; Grn1 = 1; - wait(1); + wait(.75); Red4 = 0; Red3 = 0; Yel2 = 0; Grn1 = 0; - Comm = 0; } + void swing(){ _sword.write(1.0); wait(.1); @@ -51,6 +51,7 @@ pb1.mode(PullUp); int timer = 0; + //float _baseRead = 0, _shoulderRead = 0, _elbowRead = 0; double x = 0, y = 0, z = 0; MMA8452 acc(p28, p27, 40000); //instantiate an acc object @@ -58,22 +59,16 @@ acc.setBitDepth(MMA8452::BIT_DEPTH_12); acc.setDynamicRange(MMA8452::DYNAMIC_RANGE_4G); acc.setDataRate(MMA8452::RATE_100); - - countdown(); //If master - - /* - while(Comm = 1) { - wait(.1); - } - */ + countdown(); while(1) { + acc.readXYZGravity(&x,&y,&z); //notice this is passed by reference use pointers - _base.write((y+1)/2); - _shoulder.write((x+1)/2); - _elbow.write((x+1)/4); + _base.write((-y+1)/2); + _shoulder.write((-x+1)/2); + //_elbow.write((x+1)/2); if(!pb1){ myLed=1; @@ -82,7 +77,9 @@ } // You can uncomment this line to see the values coming off the MMA8452 - //printf("\n(%.2f,%.2f,%.2f)", x,y,z); + //printf("(%.2f,%.2f,%.2f)", x,y,z); + //printf("(%.5f,%.5f,%.5f)", _baseRead, _shoulderRead, _elbowRead); + //printf("\n"); timer++; } //infinite while loop