Two player imu pong

Dependencies:   4DGL-uLCD-SE IMUfilter LSM9DS0 PinDetect mbed

Files at this revision

API Documentation at this revision

Comitter:
rrr93
Date:
Thu Oct 22 16:50:22 2015 +0000
Commit message:
qewrt

Changed in this revision

4DGL-uLCD-SE.lib Show annotated file Show diff for this revision Revisions of this file
IMUfilter.lib Show annotated file Show diff for this revision Revisions of this file
LSM9DS0.lib Show annotated file Show diff for this revision Revisions of this file
Paddle.cpp Show annotated file Show diff for this revision Revisions of this file
PinDetect.lib Show annotated file Show diff for this revision Revisions of this file
Speaker.h Show annotated file Show diff for this revision Revisions of this file
ball.cpp Show annotated file Show diff for this revision Revisions of this file
ball.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
paddle.h Show annotated file Show diff for this revision Revisions of this file
sound.cpp Show annotated file Show diff for this revision Revisions of this file
soundBuilder.h Show annotated file Show diff for this revision Revisions of this file
tempModule.cpp Show annotated file Show diff for this revision Revisions of this file
tempModule.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/4DGL-uLCD-SE.lib	Thu Oct 22 16:50:22 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/jlind6/code/4DGL-uLCD-SE/#d901d4d206e6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IMUfilter.lib	Thu Oct 22 16:50:22 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/aberk/code/IMUfilter/#8a920397b510
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LSM9DS0.lib	Thu Oct 22 16:50:22 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/aswild/code/LSM9DS0/#5556e6fb99f5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Paddle.cpp	Thu Oct 22 16:50:22 2015 +0000
@@ -0,0 +1,127 @@
+#include "paddle.h"
+
+
+Paddle::Paddle(int len, int width)
+{
+    setLength(len);
+    setWidth(width);
+    setPaddleMove(8);
+    y = 1;
+    x = 118;
+    oldy = y;
+    resetScore();
+    
+    
+    }
+    
+Paddle::Paddle(int len, int wid, int xi, int yi)
+{
+    setLength(len);
+    setWidth(wid);
+    setPaddleMove(8);
+    y = yi;
+    x = xi;
+    oldy = y;
+    resetScore();
+   
+    }
+//set functions
+void Paddle::setLength(int len)
+{ 
+length = len;
+
+}
+void Paddle::setWidth(int wid)
+{
+    width = wid;
+    }
+    
+void Paddle::setPaddleMove(int move)
+{
+    paddleMove = move;
+    }
+/*
+void Paddle::setLimits(int top, int bot)
+{
+    topLimit = top;
+    bottomLimit = bot;
+}
+*/
+// get Function
+int Paddle::getScore()
+{
+    return score;
+    
+    }
+//Member Functions
+void Paddle::movePaddle(bool mv)
+{
+    if (mv)
+        {if(y > paddleMove)
+            {y -=paddleMove;} // end of inner if
+        } // end of outer if
+    else
+       {
+           if(y < 127 - paddleMove - length)
+           { y+= paddleMove;}
+        }//end of else
+    }//ends function
+    
+bool Paddle::checkHitX(int xpos, int ypos, int radius, bool left)
+{
+    
+    if (left)
+    {
+        if ((xpos <= x+radius+width) && (ypos <= y +length) && (ypos>=y)) 
+        {  score = score +1;
+         return true;
+         }
+        else
+        {   return false;}
+        
+        }
+    else {
+        if ((xpos>= x-radius) && (ypos <= y +length) && (ypos>=y)) 
+        {  score = score +1;
+         return true;
+         }
+        else
+        {   return false;}
+    }
+}
+
+bool Paddle::checkHitY(int xpos, int ypos, int radius)
+{
+      if (((xpos >= x) && (xpos <= x+3)) && 
+                ((ypos>=y) && (ypos<=y +length)))  
+        { return true;}
+      else
+         {return false;}
+}
+
+void Paddle::resetScore()
+{ score = 0;
+
+}
+
+void Paddle::initDraw(uLCD_4DGL *screen)
+{
+    screen->filled_rectangle(x, y, x+width, y+length, BLUE);
+    
+    }
+
+void Paddle::redraw(uLCD_4DGL *uLCD)
+{
+            if(oldy > y) {
+                uLCD->filled_rectangle(x, oldy-paddleMove+1, x+width, oldy, BLUE);
+                uLCD->filled_rectangle(x, oldy+length-paddleMove+1, x+width, oldy+length, BLACK);
+                oldy = y;
+            }
+            else if(oldy < y) {
+                uLCD->filled_rectangle(x, oldy, x+width, oldy+paddleMove, BLACK);
+                uLCD->filled_rectangle(x, oldy+length,x+width, oldy+length+paddleMove, BLUE);
+                oldy = y;
+            }
+      }
+      
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinDetect.lib	Thu Oct 22 16:50:22 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Speaker.h	Thu Oct 22 16:50:22 2015 +0000
@@ -0,0 +1,23 @@
+#include "mbed.h"
+// new class to play a note on Speaker based on PwmOut class
+#ifndef _SPEAKER_H
+#define _SPEAKER_H
+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;
+};
+
+#endif // _SPEAKER_H
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ball.cpp	Thu Oct 22 16:50:22 2015 +0000
@@ -0,0 +1,183 @@
+
+#include "ball.h"
+//#include "tempModule.h"
+
+
+
+Ball::Ball(PinName pin)
+{  
+    //tempSensor = new TempModule(pin);
+    setBaseVx(2.0);
+    setBaseVy(2.0);
+    setVySign(1);
+    setVxSign(1);
+    radius = 5;
+    setX(50);
+    setY(21);
+    }
+    
+Ball::Ball(PinName pin, float Vx, float Vy, int rad,int xp, int yp)
+{
+    //tempSensor = new TempModule(pin , Vx, Vy);
+    setBaseVx(Vx);
+    setBaseVy(Vy);
+    setVxSign(1);
+    setVySign(1);
+    radius = rad;
+    setX(xp);
+    setY(yp);
+    
+    
+    }
+    
+// set functions
+void Ball::setX(int xp)
+{
+    x = xp;
+    }
+void Ball::setY(int yp)
+{
+    y = yp;
+    
+    }
+void Ball::setRand(int seed)
+{
+    srand(seed);
+    int random = (rand() % (118 - 2*radius)) + radius; 
+    setX(random);
+    int random2 = (rand() % (127 - 2*radius)) + radius;
+    setY(random2);
+    
+    }
+void Ball::setBaseVx(float Vx)
+{
+    basevx = Vx;
+    //tempSensor->setBaseVx(vxSign*Vx);
+    
+    }
+    
+    
+void Ball::setBaseVy(float Vy)
+{
+    basevy = Vy;
+    //tempSensor->setBaseVy(Vy);
+    
+    }
+    
+void Ball::setVxSign(int s)
+{
+    vxSign = s;
+    }
+    
+void Ball::setVySign(int s)
+{
+    vySign = s;
+    
+    }
+    
+    
+//get functions
+
+int Ball::getVx()
+{
+    return basevx;
+    }
+    
+int Ball::getVy()
+{
+    return basevy;
+    }
+
+int Ball::getFutureX()
+{
+    return vxSign * getVx() + x ;
+    //return vxSign * tempSensor->getVx() + x ;
+    
+    }
+    
+int Ball::getFutureY()
+{
+    return vySign * getVy() + y;
+    //return vySign * tempSensor->getVy() + y;
+    
+    }
+
+int Ball::getRadius()
+{
+    return radius;
+    }
+//Member Functions
+
+void Ball::reverseXDirection()
+{
+    
+    vxSign = - vxSign;
+    
+    }
+void Ball::reverseYDirection()
+{
+    vySign = -vySign;
+    
+    }
+/*    
+void Ball::reset( int x, int y, int vx, int vy, uLCD_4DGL*)
+{
+    
+    setBaseVx(vx);
+    setBaseVy(vy);   
+    uLCD.circle(x,y,radius,WHITE);
+    
+    
+     }
+   */  
+void Ball::update(uLCD_4DGL *uLCD)
+{
+    uLCD->circle(x,y,radius,BLACK);
+    x = (int) getFutureX();
+    y = (int) getFutureY();
+    uLCD->circle(x,y,radius,WHITE);
+    
+    
+    }
+/*
+void Ball::dispTemp(uLCD_4DGL *uLCD)
+{
+    
+    float garbage = tempSensor->getVx(uLCD);
+    
+    }
+    */
+bool Ball::CheckHit()
+{       bool hit = false;
+        /*
+        if ((getFutureX()<=radius+1)) 
+            {
+              reverseXDirection();
+              hit = true;
+            }
+            */
+        if ((getFutureY()<=radius+1) || (getFutureY()>=126-radius)) 
+            {
+                reverseYDirection();
+                hit = true;
+            }
+            return hit;
+    
+    }
+bool Ball::CheckLose()
+{
+        if ((getFutureX()>=126-radius)) 
+            {
+                //vx = 0;
+                //vy = 0;
+                return true;
+            }
+            
+        if ((getFutureX() <= radius))
+            {
+                return true;
+            }
+        else
+            {return false;}
+    }
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ball.h	Thu Oct 22 16:50:22 2015 +0000
@@ -0,0 +1,53 @@
+#include "tempModule.h"
+#include "uLCD_4DGL.h"
+
+class Ball
+{
+public:    
+    // Constructors
+    //Ball ();
+   // Ball (float, float, int);
+    /* For Part 3: 
+     * you need to be able to pass a pin to the 
+     * tempModule object from main, so you should
+     * add in a PinName argument.
+     */
+    Ball(PinName);
+    Ball(PinName, float, float, int, int, int);
+    //*/
+    // Set Functions
+    void setBaseVx(float); // This sets the lowest velocity of vx (for Thermal pong) or the constant velocity
+    void setBaseVy(float); // This sets the lowest velocity of vy (for Thermal pong) or the constant velocity
+    void setVxSign(int); 
+    void setVySign(int);
+    void setX (int);
+    void setY (int);
+    void setRand(int seed);
+    // Get Functions
+    int getVx();
+    int getVy();
+    int getFutureX();   // get estimate of where the ball will be in the next update()
+    int getFutureY();   // get estimate of where the ball will be in the next update()
+    int getRadius();
+    // Member Functions
+    void reverseXDirection(); // negate the sign for when a ball hits something
+    void reverseYDirection(); // negate the sign for when a ball hits something
+    //void reset(int, int, int, int, uLCD_4DGL *); // takes in a new location and new directions and draws the starting point for the ball
+    void dispTemp(uLCD_4DGL *);
+    void update(uLCD_4DGL *); // moves the ball on the screen one vx and vy
+    bool CheckHit(); //check if the ball hit walls
+    bool CheckLose(); //check if the ball is out of bounds
+private:
+    // Data members are suggestions, feel free to add/remove
+    TempModule *tempSensor; // Pointer -- it's recommended to use "new" operator to create this
+    int vxSign;
+    int vySign;
+    float basevx;
+    float basevy;
+    float fx;
+    float fy;
+    int x;
+    int y;
+    int radius;
+    bool lose;
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 22 16:50:22 2015 +0000
@@ -0,0 +1,260 @@
+#include "mbed.h"
+#include "PinDetect.h"
+#include "uLCD_4DGL.h"
+#include "Speaker.h"
+#include "paddle.h"
+#include "ball.h"
+#include "soundBuilder.h"
+#include "LSM9DS0.h"
+
+Serial pc(USBTX, USBRX);
+//IMU
+// SDO_XM and SDO_G are pulled up, so our addresses are:
+#define LSM9DS0_XM_ADDR  0x1D // Would be 0x1E if SDO_XM is LOW
+#define LSM9DS0_G_ADDR   0x6B // Would be 0x6A if SDO_G is LOW
+LSM9DS0 imu(p9, p10, LSM9DS0_G_ADDR, LSM9DS0_XM_ADDR);
+LSM9DS0 imu2(p28,p27, LSM9DS0_G_ADDR, LSM9DS0_XM_ADDR);
+
+// Pushbuttons
+PinDetect pbUp(p15); 
+PinDetect pbDown(p16);
+// uLCD
+uLCD_4DGL uLCD(p13, p14, p29);
+//Speaker
+Speaker mySpeaker(p21);
+ 
+// Global variables needed for the push button interrupts
+ Paddle paddle(40, 3, 118,1);
+ Paddle paddle2(40,3, 8, 1);
+ Ball ball(p19, 1.6,1.2,5,50,21);
+ 
+// State machine definitions
+enum gameStateType {START, WAIT, GAME_SETUP, GAME, LOSE};
+/* State Definitions:
+ * START -- Creates the start screen
+ * WAIT -- After the start screen, goes into wait where mbed spins and does nothing
+ * GAME_SETUP -- Sets up one time things (like boarders, initializes beginning velocity
+ * GAME -- When the user actually gets to play
+ * LOSE -- clears the screen, prints you lose, waits, then goes back to start
+ */
+ 
+// Global state machine variable (So that the pushbuttons can modify it)
+gameStateType gameState = START;
+
+// Pushbutton callbacks
+// WARNING: Do not call to draw anything to the uLCD in these
+// as this will cause the uLCD to crash sometimes. Update positions
+// and draw elsewhere (like it's done here).
+// Only modify the logic inside the callback functions.
+void pbUp_hit_callback (void)
+{
+    switch (gameState)
+    {
+    case WAIT:
+        gameState = GAME_SETUP;
+        break;
+    case GAME:  
+        paddle.movePaddle(true);
+        paddle2.movePaddle(true);
+        break;
+    }
+}
+ 
+void pbDown_hit_callback (void)
+{
+    switch (gameState)
+    {
+    case WAIT:
+        gameState = GAME_SETUP;
+        break;
+    case GAME:
+        paddle.movePaddle(false);
+        paddle2.movePaddle(false);
+        break;
+    }
+}
+ 
+int main() 
+{   
+    
+    //IMU
+    uint16_t status = imu.begin();
+    //Make sure communication is working
+    pc.printf("LSM9DS0 WHO_AM_I's returned: 0x%X\n", status);
+    pc.printf("Should be 0x49D4\n\n");
+    
+    uint16_t status2 = imu2.begin();
+    //Make sure communication is working
+    pc.printf("LSM9DS0 #2 WHO_AM_I's returned: 0x%X\n", status2);
+    pc.printf("Should be 0x49D4\n\n");
+    
+    
+    
+    float IMU_offset = 0.14; //detrmined empirically
+    
+    // This is setting up the pushbuttons
+    // Don't modify this code.
+    pbUp.mode(PullUp);
+    pbDown.mode(PullUp);
+    wait(0.1);
+    pbUp.attach_deasserted(&pbUp_hit_callback);
+    pbDown.attach_deasserted(&pbDown_hit_callback);
+    pbUp.setSampleFrequency();
+    pbDown.setSampleFrequency();
+    // Don't modify this code.
+    
+    uLCD.display_control(PORTRAIT);
+    uLCD.cls();
+    uLCD.baudrate(BAUD_3000000);
+    uLCD.background_color(BLACK);
+
+    // Initialize all your variables outside the while/switch statement
+    // to avoid compiler warning/errors
+    int i = 0;
+    int random;
+    
+    //paddle stuff
+    int pmoveMin = 25;
+    int pmoveMax = 70;
+    int pmove;
+ 
+    while (1) 
+    {   
+        switch (gameState)
+        {
+        case START:
+            uLCD.cls();
+            uLCD.locate(0,0);
+            uLCD.printf("Pong!!!\n\n");
+            uLCD.printf("Press Key to Start");
+            gameState = WAIT;
+            ball.setX(50);
+            ball.setY(50);
+            break;
+        case GAME_SETUP:
+            uLCD.cls();
+            uLCD.line(0, 0, 127, 0, 0xCFB53B);
+            uLCD.line(127, 0, 127, 127, 0xCFB53B);
+            uLCD.line(127, 127, 0, 127, 0xCFB53B);
+            uLCD.line(0, 127, 0, 0, 0xCFB53B);
+            ball.setBaseVx(2.0);
+            ball.setBaseVy(2.0);
+            random = rand() % 1;
+            ball.setVxSign(-1); ball.setVySign(((float)random - 0.5)*2);
+            paddle.initDraw(&uLCD);
+            paddle2.initDraw(&uLCD);
+            
+            Note note1(4000.0, 0.7, 0.5);
+            Note note2(3000.0, 0.3, 0.5);
+            Note note3(2000.0, 0.3, 0.5);
+            Note note4(1000.0, 0.7, 0.5);
+            Note note5(2500.0, 0.3, 0.5);
+            SoundBuilder sound(&mySpeaker);
+            sound.addNote(note1);
+            sound.addNote(note2);
+            sound.addNote(note3);
+            sound.addNote(note4);
+            sound.addNote(note5);
+            sound.playSong();
+            gameState = GAME;
+            break;
+        case GAME:
+            if(ball.CheckHit())
+            {      
+               Note note(1000.0, 0.03, 0.5);
+               SoundBuilder sound(&mySpeaker);
+               sound.addNote(note);
+               sound.playSong();
+            }
+
+            if (paddle.checkHitY(ball.getFutureX(), ball.getFutureY(), ball.getRadius())) 
+            {   
+                
+                ball.reverseYDirection();
+            }
+            
+            if (paddle2.checkHitY(ball.getFutureX(), ball.getFutureY(), ball.getRadius())) 
+            {   
+                
+                ball.reverseYDirection();
+            }
+
+            if (ball.CheckLose())
+                {gameState = LOSE;}
+            if (paddle.checkHitX(ball.getFutureX(), ball.getFutureY(), ball.getRadius(),false)) 
+            {
+               Note note(4000.0, 0.03, 0.5);
+               SoundBuilder sound(&mySpeaker);
+               sound.addNote(note);
+               sound.playSong();
+                
+                ball.reverseXDirection();
+                uLCD.locate(1,1);
+            }
+            
+            if (paddle2.checkHitX(ball.getFutureX(), ball.getFutureY(), ball.getRadius(),true)) 
+            {
+               Note note(4000.0, 0.03, 0.5);
+               SoundBuilder sound(&mySpeaker);
+               sound.addNote(note);
+               sound.playSong();
+                ball.reverseXDirection();
+                uLCD.locate(1,1);
+            }
+            
+            
+            ball.update(&uLCD);
+            imu.readAccel();
+
+            imu2.readAccel();
+
+            if ( imu.ax + IMU_offset > 0.1)
+            {
+                paddle.movePaddle(true);
+            }
+            else if (imu.ax+ IMU_offset  < -0.1)
+            {
+               paddle.movePaddle(false); 
+            }
+            
+            if ( imu2.ax + IMU_offset > 0.1)
+            {
+                paddle2.movePaddle(true);
+            }
+            else if (imu2.ax+ IMU_offset  < -0.1)
+            {
+               paddle2.movePaddle(false);    
+            }
+            
+            // We can assume that these for loops are quick enough that the paddle will move only one interval.
+            // These movements of the paddle have been optimized. Feel free to draw it out to see how it's been done.
+            paddle.redraw(&uLCD);
+            paddle2.redraw(&uLCD);
+            break;
+        case LOSE:
+            uLCD.cls();
+            uLCD.printf("YOU LOSE D:");
+            Note note6(3000.0, 0.7, 0.5);
+            Note note7(2000.0, 0.3, 0.5);
+            Note note8(1000.0, 0.3, 0.5);
+            Note note9(2300.0, 0.7, 0.5);
+            Note note10(2500.0, 0.3, 0.5);
+            SoundBuilder sound2(&mySpeaker);
+            sound2.addNote(note6);
+            sound2.addNote(note7);
+            sound2.addNote(note8);
+            sound2.addNote(note9);
+            sound2.addNote(note10);
+            sound2.playSong();
+            paddle.resetScore();
+            paddle2.resetScore();
+            wait(5.0);
+            gameState = START;
+            break;
+        case WAIT:
+            // Used to seed the rand() function so we don't get the same starting position every time.
+            i++; 
+            break;
+        }
+    } 
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 22 16:50:22 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paddle.h	Thu Oct 22 16:50:22 2015 +0000
@@ -0,0 +1,37 @@
+#include "uLCD_4DGL.h"
+
+class Paddle 
+{
+public:
+    // Constructors
+    Paddle(int, int);
+    Paddle(int, int, int, int);
+    // Set Functions
+    void setLength(int);
+    void setWidth(int);
+    void setPaddleMove(int);  
+    void setLimits(int, int); // upper and lower limits of the paddle
+    // Get Function
+    int getScore();
+    // Member Functions
+    void movePaddle(bool); // moves the paddle locations (does not draw!)
+    bool checkHitX(int, int, int, bool); // Using a position and radius, checks to see if something has hit the paddle in the x direction. The bool is to determine if it is the left or right paddle
+    bool checkHitY(int, int, int); // Using a position and radius, checks to see if something has hit the paddle in the y direction
+    void resetScore(); // sets score to 0
+    void initDraw(uLCD_4DGL *uLCD); // draw the paddle initially (draws the whole thing)
+    void redraw(uLCD_4DGL *uLCD); // draws the paddle for a move (does NOT draw the whole thing)
+    
+
+private:
+    // Data members are suggestions, feel free to add/remove
+    int score;
+    int x;
+    int y;
+    int oldy;
+    int length;
+    int width;
+    int paddleMove;
+    int topLimit;
+    int bottomLimit;
+};
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sound.cpp	Thu Oct 22 16:50:22 2015 +0000
@@ -0,0 +1,53 @@
+#include "soundBuilder.h"
+
+
+Note::Note()
+{
+    freq = 333;
+    length = 3;
+    volume = 1;
+    }
+Note::Note(float f, float len, float vol)
+{
+    freq =f;
+    length = len;
+    volume = vol;
+    
+    }
+//get
+float Note::getFreq()
+{
+    return freq;
+    }
+float Note::getLength()
+{
+    return length;
+    }    
+float Note::getVol()
+{
+    return volume;
+    }
+    
+SoundBuilder::SoundBuilder()
+{
+    ind = 0;
+    
+    }
+SoundBuilder::SoundBuilder(Speaker *speakerin)
+{
+    ind = 0;
+    speaker = speakerin;
+    }
+void SoundBuilder::addNote(Note note)
+{
+    song[ind] = note;
+    ind = ind+1;
+    }
+void SoundBuilder::playSong()
+{
+    for (int i = 0; i < ind; i++)
+    {
+        speaker->PlayNote(song[i].getFreq(), song[i].getLength(), song[i].getVol());
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/soundBuilder.h	Thu Oct 22 16:50:22 2015 +0000
@@ -0,0 +1,36 @@
+#include "Speaker.h"
+
+class Note
+{
+public:
+    Note();
+    Note(float, float, float);
+    float getFreq();
+    float getLength();
+    float getVol();
+    // You create your own constructors and 
+    // member functions!!
+private:
+    float freq;
+    float length;
+    float volume;
+};
+
+class SoundBuilder
+{
+public:
+    SoundBuilder();
+    SoundBuilder(Speaker *);
+    void addNote(Note);
+    void playSong();
+    // Set Sounds
+    // Set Songs
+    // Play Sounds
+    // Play Songs
+    // Clear Songs
+
+private:
+    Note song[20];
+    Speaker *speaker;
+    int ind;
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tempModule.cpp	Thu Oct 22 16:50:22 2015 +0000
@@ -0,0 +1,55 @@
+#include "tempModule.h"
+
+
+TempModule::TempModule (PinName pin) : _sensor(pin)
+{
+    // Constructor code goes here
+    // you can ignore initializing _sensor, we've already done that
+    roomTemp = 26.0;
+    setBaseVx(2.0);
+    setBaseVy(2.0);
+}
+
+TempModule::TempModule (PinName pin, float vx, float vy) : _sensor(pin)
+{
+    // Constructor code goes here
+    // you can ignore initializing _sensor, we've already done that
+    roomTemp = 26.0;
+    setBaseVx(vx);
+    setBaseVy(vy);
+    
+}
+
+float TempModule::read()
+{
+    return ((_sensor.read()*3.3)-0.500)*100.0; //temp in degree C
+    }
+    
+//Set functions
+void TempModule::setBaseVx(float vx)
+{
+    basevx = vx;
+    }
+void TempModule::setBaseVy(float vy)
+{
+    basevy = vy;
+    }
+//Get Functions
+float TempModule::getVx()
+{
+    return ((( roomTemp - read()) / 10) + basevx);
+    
+    }  
+    
+float TempModule::getVy()
+{
+   return (((roomTemp - read()) / 10) + basevy);
+   }
+float TempModule::getVx (uLCD_4DGL *uLCD) 
+{  uLCD->locate(1,14);
+   uLCD->printf("%f", read());
+   return (((read()-roomTemp) / 10) + basevx);
+   
+    
+    } 
+    
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tempModule.h	Thu Oct 22 16:50:22 2015 +0000
@@ -0,0 +1,41 @@
+#include "uLCD_4DGL.h"
+
+/* Recommendation:
+ * This class doesn't need to be declared outside the Ball class,
+ * so you can create it inside the Ball class and use it only
+ * in the Ball class.
+ *
+ * If the main function or multiple objects use a piece of hardware
+ * or a class object (like uLCD or mySpeaker), you should pass a 
+ * pointer into the object rather than creating the object (either
+ * in the stack or using new).
+ */
+
+class TempModule 
+{
+public:
+    // Constructors
+    TempModule(PinName pin);
+    TempModule(PinName pin, float vx, float vy);
+    // Reading temperature values
+    float read();
+    // Set Functions
+    void setBaseVx(float); // This sets the lowest velocity of vx
+    void setBaseVy(float); // This sets the lowest velocity of vy
+    // Get Functions/Member Functions
+    float getVx();  // Calculates a speed based off of the temp
+    float getVy();   
+    float getVx(uLCD_4DGL *); // Same thing as getVx(), except it 
+                              // also writes the temp to the screen.
+
+private:
+    // Data members are suggestions, feel free to add/remove
+    AnalogIn _sensor; //_pin
+    float roomTemp;
+    float holdTemp;
+    float basevx;
+    float basevy;
+    int counter;
+};
+
+