This a Library that can be used to make ping pong the Nokia Lcd 5110.
Revision 0:ef8d5a4464a3, committed 2016-05-04
- Comitter:
- el14jpps
- Date:
- Wed May 04 23:22:04 2016 +0000
- Child:
- 1:4893a8f7147f
- Commit message:
- Ping Pong library by Jefferson Sanchez
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Ball.cpp Wed May 04 23:22:04 2016 +0000
@@ -0,0 +1,78 @@
+
+/**
+**
+@file Ball.cpp
+@brief File containing all the functions prototypes , void etc for the ball.
+@brief Shows examples of creating Doxygen documentation.
+@brief Revision 1.0.
+@author Jefferson Sanchez
+@date April 2016
+*/
+
+
+#include "Ball.h"
+// @paramFunction to set the x value
+void ball::setX(int value)
+{
+ x = value;
+}
+// Function to set the y value
+void ball::setY(int value)
+{
+ y = value;
+}
+// Function to look for or check for the x value to be later used on the code .
+int ball::lookforX()
+{
+ return x;
+}
+// Function to look for or check for the y value to be later used on the code
+
+int ball::lookforY()
+{
+ return y;
+}
+// Function to look for or check for the x value to ve later used on the code
+
+int ball::lookforPos_stateX()
+{
+ return x_Pos_state;
+}
+
+int ball::lookforPos_stateY()
+{
+ return y_Pos_state;
+}
+
+void ball::BallcollisionState(int xPos_state, int yPos_state)
+{
+ x_Pos_state = xPos_state;
+ y_Pos_state = yPos_state;
+}
+
+void ball::dbal(N5110 &display)
+{
+ // this states the diameter of the ball
+ for(int i = -3; i < 3; i++)
+ for(int j = -3; j < 3; j++)
+ display.setPixel(x + j, y + i);
+
+ display.refresh();
+}
+
+void ball::clear_dbal(N5110 &display)
+{
+ //states the clearing of the ball as it moves
+ for(int i = -3; i < 3; i++)
+ for(int j = -3; j < 3; j++)
+ display.clearPixel(x + j, y + i);
+
+ display.refresh();
+}
+
+void ball::Refresh_pos()
+{
+ x += x_Pos_state;
+ y += y_Pos_state;
+}
+// end of code
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Ball.h Wed May 04 23:22:04 2016 +0000
@@ -0,0 +1,81 @@
+/**
+@file Ball.h
+@brief Header file containing functions for the ball.
+
+*/
+
+#ifndef BALL_H
+#define PADDLE_H
+
+#include "mbed.h"
+#include "N5110.h"
+
+/**
+@brief This library has been made to allow the ball to update, check its position. etc This will make the coding later on in the main file a bit easier to manipulate.
+@brief Revision 1.0
+@author Jefferson Sanchez
+@date April 2016
+ **/
+
+class ball
+{
+ /** Ball will give me the integers for x1,y1,xi position, y1 position .
+ */
+ int x, y;
+ int x_Pos_state, y_Pos_state;
+public:
+ /** Ball will give me the integers for x1,y1,x1 position, y1 position .
+ * @param pin connected to PTB3 in a Digital Input
+ * @param Pin Connected to PTB2 in a Digital Input
+ * @param Pins connected to +5v and GND to be able to obtain an integer value.
+ */
+ ball(int x1, int y1, int x1_Pos_state, int y1_Pos_state) : x(x1), y(y1), x_Pos_state(x1_Pos_state), y_Pos_state(y1_Pos_state) {}
+
+ /** Switches a pixel on in a particular coordinate in the X axis.
+ *
+ * ball.setX(41);
+ */
+ void setX(int value);
+ /** Switches a pixel on in a particular coordinate in the Y axis.
+ *
+ * ball.setY(23);
+ *
+ */
+ void setY(int value);
+ /** Switches a pixel on in a particular coordinate in the X axis.
+ *
+ * ball.setY(23);
+ *
+ */
+ int lookforX();
+ /**
+ *@param Allows me to check to see what pixels are on in the Y coordinate.
+ @returns y value.
+ */
+ int lookforY();
+ /**
+ *@param Checks the position state on the X coordinate.
+ *@returns x position state.
+ */
+ int lookforPos_stateX();
+ /** Checks the position state on the Y coordinate.
+ @returns y position state.
+ */
+ int lookforPos_stateY();
+ /** Checks the Collisions state on the X and Y coordinates.
+ */
+
+ void BallcollisionState(int xPos_state, int yPos_state);
+ /** Diameter of the ball.
+ */
+ void dbal(N5110 &display);
+ /** States the clearing of pixels for the ball as it moves
+ */
+ void clear_dbal(N5110 &display);
+ /** This is used to refresh the position of the ball.
+ */
+ void Refresh_pos();
+
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Paddle.cpp Wed May 04 23:22:04 2016 +0000
@@ -0,0 +1,77 @@
+/**
+**
+@file Paddle.cpp
+@brief File containing all the functions prototypes, void etc for the ball.
+@brief Shows examples of creating Doxygen documentation.
+@brief Revision 1.0.
+@author Jefferson Sanchez
+@date April 2016
+*/
+
+#include "Paddle.h"
+int Paddle::lookforX1()// as the function states the integer needed will change in x1,x2,y1,y2
+{
+ return x1;
+}
+
+int Paddle::lookforX2()
+{
+ return x2;
+}
+
+int Paddle::lookforY1()
+{
+ return y1;
+}
+
+int Paddle::lookforY2()
+{
+ return y2;
+}
+
+void Paddle::YPaddle(N5110 &display)
+{
+ for(int i = y1; i <= y2; i++)
+ {
+ display.setPixel(x1, i);
+ display.setPixel(x2, i);
+ }
+
+ display.refresh();
+}
+
+void Paddle::Moving_Paddle(N5110 &display) // used for the movement of the paddles.
+{
+ for(int i = y1; i <= y2; i++)
+ {
+ display.clearPixel(x1, i);
+ display.clearPixel(x2, i);
+ }
+
+ display.refresh();
+}
+
+void Paddle::Refresh_pos(AnalogIn &p1)// in this void we can see the uodate of the paddle for player 1
+{
+ //
+ if (p1 < 0.33)//The threshold of potentiometer P1 , the 0.33 value was obtained using Dr Evans code for the joystick and cool term.
+ {
+ y1 -= 2;
+ y2 -= 2;
+ if(y1 < 0 or y2 < 7){
+ y1 = 0;
+ y2 = 7;
+ }
+ }
+
+ if (p1 > 0.66)//The threshold of potentiometer P2 , the 0.66 value was obtained using Dr Evans code for the joystick and cool term.
+ {
+ y1 += 2;
+ y2 += 2;
+ if(y2 > 47 or y1 > 40)
+ {
+ y2 = 47;
+ y1 = 40;
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Paddle.h Wed May 04 23:22:04 2016 +0000
@@ -0,0 +1,65 @@
+
+/**
+@file Paddle.h
+@brief Header file containing functions.
+*/
+/**Identifications for the paddle library.
+*/
+#ifndef PADDLE_H
+#define PADDLE_H
+
+#include "mbed.h"
+#include "N5110.h"
+
+/**
+@brief This library has been made to allow the paddle to update, check its position .etc This will make the coding later on in the main file a bit easier to manipulate.
+@brief Revision 1.0
+@author Jefferson Sanchez
+@date April 2016
+ **/
+
+// the class is used to store a type of variable in this case the variable is the “paddle"
+class Paddle
+{
+ int x1, x2, y1, y2;// the integers are x and y
+public:
+ /** The following show the connections to the K64F
+ *
+ * @param pin connected to PTB3 in a Digital Input
+ * @param Pin Connected to PTB2 in a Digital Input
+ * @param Pin connected to +5v and GND to be able to obtain a interger value.
+ *
+ */
+ Paddle(int x_1, int x_2, int y_1, int y_2) : x1(x_1), x2(x_2), y1(y_1), y2(y_2) {}
+ /** Checks to see what pixels are on in the X coordinate for player 1 and returns a value for X1.
+ */
+ int lookforX1();
+ /** Allows to check to see what pixels are on in the X coordinate for player 2 and returns a value for X2.
+ */
+ int lookforX2();
+ /** Checks to see what pixels are on in the Y coordinate for player 1 and returns a value for Y1 .
+ */
+ int lookforY1();
+ /** Check to see what pixels are on in the Y coordinate for player 2 and returns a value for Y2.
+ */
+ int lookforY2();
+ /** Once the coordinates have been obtained it will display them on the lcd.
+ * for(int i = y1; i <= y2; i++)
+ * {
+ * display.setPixel(x1, i);
+ * display.setPixel(x2, i);
+ * }
+
+ display.refresh();
+ }
+ */
+ void YPaddle(N5110 &display);
+ /** Once the coordinates have been obtained it will update the display when the paddle moves.
+ */
+ void Moving_Paddle(N5110 &display);
+ /** This function allow me to refresh the position of Player 1 */
+ void Refresh_pos(AnalogIn &p1);
+
+};
+
+#endif
Jefferson Sanchez