Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 5:7207c9b70108, committed 2020-05-27
- Comitter:
- ChenZirui
- Date:
- Wed May 27 21:13:59 2020 +0000
- Parent:
- 4:e46c295d4baf
- Child:
- 6:b393cfe4e0a7
- Commit message:
- problems
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Board/Board.cpp Wed May 27 21:13:59 2020 +0000
@@ -0,0 +1,106 @@
+#include "Board.h"
+
+// nothing doing in the constructor and destructor
+Board::Board()
+{
+
+}
+
+Board::~Board()
+{
+
+}
+
+void Board::init(int x,int y,int height,int width,N5110 &lcd)
+{
+ _x=x ; // horizontal coordinate of Board
+ //_y=48-height/2 ; // vertical coordinate of fighte
+ _y=y ;
+ _height =height;
+ _width = width;
+ _speed = 1; // default speed
+ _score = 0;
+ //lcd.drawRect(0,0,84,24,FILL_BLACK);
+
+ }
+ void Board::draw(N5110 &lcd)
+ {
+ //lcd.drawRect(_x+(_height/2)-(_width/2),_y,_width,_height,FILL_BLACK);
+ lcd.drawRect(_x,_y,_height,_width,FILL_BLACK);
+ // lcd.drawRect(0,0,84,24,FILL_BLACK);
+ // lcd.drawRect(41,24,10,10,FILL_TRANSPARENT);
+ // lcd.clearPixel(10,24);
+
+
+ }
+ void Board::update(Direction d,float mag,N5110 &lcd)
+ {
+ _speed = int(mag*10.0f); // scale is arbitrary, could be changed in future
+ //if((ball_pos.y >= 0)&&(ball_pos.y <= 24))
+ // {
+ // lcd.drawRect(24,41,10,10,FILL_TRANSPARENT);
+ // }
+ lcd.clearPixel(10,24);
+
+ // update y value depending on direction of movement
+ // North is decrement as origin is at the top-left so decreasing moves up
+ if (d == N)
+ {
+ _y-=_speed;
+ }else if (d == S)
+ {
+ _y+=_speed;
+ }else if(d == W)
+ {
+ _x-=_speed;
+ }else if(d == E)
+ {
+ _x+=_speed;
+ }else if(d == NE)
+ {
+ _y+=_speed;
+ _x+=_speed;
+ }else if(d == NW)
+ {
+ _y+=_speed;
+ _x-=_speed;
+ }else if(d == SE)
+ {
+ _y-=_speed;
+ _x+=_speed;
+ }else if(d == SW)
+ {
+ _y-=_speed;
+ _x-=_speed;
+ }
+ if (_y < 1)
+ {
+ _y = 1;
+ }
+ if (_y > HEIGHT - _height - 1)
+ {
+ _y = HEIGHT - _height - 1;
+ }
+ if (_x < 1)
+ {
+ _x = 1;
+ }
+ if (_x > WIDTH - _width - 1)
+ {
+ _x = WIDTH - _width - 1;
+ }
+}
+ void Board::add_score()
+ {
+ _score++;
+ }
+ int Board::get_score()
+ {
+ return _score;
+ }
+
+ Vector2D Board::get_pos()
+ {
+ Vector2D p = {_x,_y};
+ return p;
+ }
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Board/Board.h Wed May 27 21:13:59 2020 +0000
@@ -0,0 +1,33 @@
+#ifndef BOARD_H
+#define BOARD_H
+
+#include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+#include "Bullet.h"
+
+class Board
+{
+public:
+
+ Board();
+ ~Board();
+ void init(int x,int y,int height,int width,N5110 &lcd);
+ void draw(N5110 &lcd);
+ void update(Direction d,float mag,N5110 &lcd);
+ void add_score();
+ int get_score();
+ Vector2D get_pos();
+
+private:
+
+ int _height;
+ int _width;
+ int _x;
+ int _y;
+ int _speed;
+ int _score;
+ //bullet _bullet;
+
+};
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Bullet/Bullet.cpp Wed May 27 21:13:59 2020 +0000
@@ -0,0 +1,84 @@
+#include "Bullet.h"
+
+Bullet::Bullet()
+{
+
+}
+
+Bullet::~Bullet()
+{
+
+}
+
+void Bullet::init(int x,int size,int speed,int height)
+{
+ _size = size;
+
+ _x = x+(height)*0.5;
+ _y = HEIGHT - size;
+
+ srand(time(NULL));
+ int direction = rand() % 4; // randomise initial direction.
+
+ // 4 possibilities. Get random modulo and set velocities accordingly
+ if (direction == 0) {
+ _velocity.x = speed;
+ _velocity.y = speed;
+ } else if (direction == 1) {
+ _velocity.x = speed;
+ _velocity.y = -speed;
+ } else if (direction == 2) {
+ _velocity.x = speed;
+ _velocity.y = speed;
+ } else {
+ _velocity.x = -speed;
+ _velocity.y = -speed;
+ }
+}
+
+void Bullet::draw(N5110 &lcd)
+{
+ lcd.drawRect(_x,_y,_size,_size,FILL_BLACK);
+ if((_y >= 0)&&(_y <= 24))
+ {
+ // lcd.clearPixel(_x,_y-1);
+
+ }
+ //lcd.drawRect(0,0,84,24,FILL_BLACK);
+ // lcd.clearPixel(_x,_y);
+}
+
+void Bullet::update(N5110 &lcd)
+{
+ _x += _velocity.x;
+ _y += _velocity.y;
+ if((_y >= 0)&&(_y <= 24))
+ {
+// lcd.clearPixel(_x,_y-1);
+
+ }
+}
+
+void Bullet::set_velocity(Vector2D v)
+{
+ _velocity.x = v.x;
+ _velocity.y = v.y;
+}
+
+Vector2D Bullet::get_velocity()
+{
+ Vector2D v = {_velocity.x,_velocity.y};
+ return v;
+}
+
+Vector2D Bullet::get_pos()
+{
+ Vector2D p = {_x,_y};
+ return p;
+}
+
+void Bullet::set_pos(Vector2D p)
+{
+ _x = p.x;
+ _y = p.y;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Bullet/Bullet.h Wed May 27 21:13:59 2020 +0000
@@ -0,0 +1,38 @@
+#ifndef Bullet_H
+#define Bullet_H
+
+#include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+#include "Board.h"
+
+/** Bullet Class
+@author Dr Craig A. Evans, University of Leeds
+@brief Controls the Bullet in the Pong game
+@date Febraury 2017
+*/
+class Bullet
+{
+
+public:
+ Bullet();
+ ~Bullet();
+ void init(int x,int size,int speed,int height);
+ void draw(N5110 &lcd);
+ void update(N5110 &lcd);
+ /// accessors and mutators
+ void set_velocity(Vector2D v);
+ Vector2D get_velocity();
+ Vector2D get_pos();
+ void set_pos(Vector2D p);
+
+private:
+
+ Vector2D _velocity;
+ int _size;
+ int _x;
+ int _y;
+ //Bullet Bullet;
+
+};
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Bullet/Bullet_test.h Wed May 27 21:13:59 2020 +0000
@@ -0,0 +1,49 @@
+#ifndef BULLET_TEST_H
+#define BUllET_TEST_H
+
+/**
+ * \brief Check that Ball object goes to correct position when moved
+ *
+ * \returns true if all the tests passed
+ */
+bool Bullet_test_movement()
+{
+ // Initialise Bullet object with a size of 2, and speed of 1
+ Bullet bullet;
+ bullet.init(2, 1);
+
+ // Set the position to 5, 5
+ Vector2D initial_pos = {5, 5};
+ bullet.set_pos(initial_pos);
+
+ // Read the position
+ Vector2D read_pos_1 = bullet.get_pos();
+ printf("%f, %f\n", read_pos_1.x, read_pos_1.y);
+
+ // Set the velocity to -2, 3
+ Vector2D velocity = {-2, 3};
+ bullet.set_velocity(velocity);
+
+ // Update the position
+ bullet.update();
+
+ // Read the position
+ Vector2D read_pos_2 = bullet.get_pos();
+ printf("%f, %f\n", read_pos_2.x, read_pos_2.y);
+
+ // Now check that both the positions are as expected
+ bool success_flag = true;
+
+ // Fail the test if the initial position is wrong
+ if (read_pos_1.x != 5 || read_pos_1.y != 5) {
+ success_flag = false;
+ }
+
+ // Fail the test if the final position is wrong
+ if (read_pos_2.x != 3 || read_pos_2.y != 8) {
+ success_flag = false;
+ }
+
+ return success_flag;
+}
+#endif
\ No newline at end of file
--- a/Fighter/Fighter.cpp Sat May 23 18:12:03 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,97 +0,0 @@
-#include "Fighter.h"
-
-// nothing doing in the constructor and destructor
-fighter::fighter()
-{
-
-}
-
-fighter::~fighter()
-{
-
-}
-
-void fighter::init(int x,int y,int height,int width)
-{
- _x=WIDTH/2-width/2 ; // horizontal coordinate of fighter
- _y=HEIGHT/2-height/2 ; // vertical coordinate of fighte
- _height =height;
- _width = width;
- _speed = 1; // default speed
- _score = 0;
-
-
- }
- void fighter::draw(N5110 &lcd);
- {
- lcd.drawRect(_x+(_height/2)-(_width/2),_y,_width,_height,FILL_BLACK);
- lcd.drawRect(_x,_y,_height,_width,FILL_BLACK);
-
- }
- void fighter::update(Direction d,float mag)
- {
- speed = int(mag*10.0f); // scale is arbitrary, could be changed in future
-
- // update y value depending on direction of movement
- // North is decrement as origin is at the top-left so decreasing moves up
- if (d == N)
- {
- _y-=_speed;
- }else if (d == S)
- {
- _y+=_speed;
- }else if(d == W)
- {
- _x-=_speed;
- }else if(d == E)
- {
- _x+=_speed;
- }else if(d == NE)
- {
- _y+=_speed;
- _x+=_speed;
- }else if(d == NW)
- {
- _y+=_speed;
- _x-=_speed;
- }else if(d == SE)
- {
- _y-=_speed;
- _x+=_speed;
- }else if(d == SW)
- {
- _y-=_speed;
- _x-=_speed;
- }
- if (_y < 1)
- {
- _y = 1;
- }
- if (_y > HEIGHT - _height - 1)
- {
- _y = HEIGHT - _height - 1;
- }
- if (_x < 1)
- {
- _x = 1;
- }
- if (_x > WIDTH - _width - 1)
- {
- _x = WIDTH - _width - 1;
- }
-}
- void fighter::add_score()
- {
- _score++;
- }
- int fighter::get_score()
- {
- return _score;
- }
-
- Vector2D fighter::get_pos()
- {
- Vector2D p = {_x,_y};
- return p;
- }
-
\ No newline at end of file
--- a/Fighter/Fighter.h Sat May 23 18:12:03 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-#ifndef FIGHTER_H
-#define FIGHTER_H
-
-#include "mbed.h"
-#include "N5110.h"
-#include "Gamepad.h"
-
-class fighter
-{
-
- public:
-
- fighter();
- ~fighter();
- void init(int x,int y,int height,int width);
- void draw(N5110 &lcd);
- void update(Direction d,float mag);
- void add_score();
- int get_score();
- Vector2D get_pos();
-
- private:
-
- int _height;
- int _width;
- int _x;
- int _y;
- int _speed;
- int _score;
-
- };
-#endif
\ No newline at end of file
--- a/ROCK/Rock.cpp Sat May 23 18:12:03 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-#include"ROCK.h"
-rock::rock()
-{
-
-}
-
-rock::~rock()
-{
-
-}
-
-void rock::init(int size,int speed)
-{
- srand(time(null));
- int a=rand()%84;
- int i;
- for(i=0;i<85;i++)
- {
- if(i==a)
- {
- _velocity.x=_a
- _velocity.y=speed
- }
- }
-
- }
\ No newline at end of file
--- a/ROCK/Rock.h Sat May 23 18:12:03 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-#ifndef ROCK_H
-#define ROCK_H
-
-#include "mbed.h"
-#include "N5110.h"
-#include "Gamepad.h"
-#include "Fighter.h"
-
-
-class rock
-{
-
-public:
- rock();
- ~rock();
- void init(int size,int speed);
- void draw(N5110 &lcd);
- void update();
- /// accessors and mutators
- void set_velocity(Vector2D v);
- Vector2D get_velocity();
- Vector2D get_pos();
- void set_pos(Vector2D p);
-
-private:
-
- Vector2D _velocity;
- int _size;
- int _x;
- int _y;
-};
-#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Touch/Touch.cpp Wed May 27 21:13:59 2020 +0000
@@ -0,0 +1,184 @@
+#include "Touch.h"
+
+Touch::Touch()
+{
+
+}
+
+Touch::~Touch()
+{
+
+}
+
+void Touch::init(int board_width,int board_height,int bullet_size,int speed,N5110 &lcd)
+{
+ // initialise the game parameters
+ _Board_width = board_width;
+ _Board_height = board_height;
+ _bullet_size = bullet_size;
+ _speed = speed;
+
+ // x position on screen - WIDTH is defined in N5110.h
+ _p1x = GAP;
+ _p2x = WIDTH - GAP - _Board_width;
+ _p1y=48-board_height*0.5;
+ // puts boards and ball in middle
+ _p1.init(_p1x,_p1y,_Board_height,_Board_width,lcd);
+ //lcd.drawRect(0,0,84,24,FILL_BLACK);
+ _bullet.init(_p1x,board_height,_speed,_Board_height);
+}
+
+void Touch::read_input(Gamepad &pad)
+{
+ _d = pad.get_direction();
+ _mag = pad.get_mag();
+}
+
+void Touch::draw(N5110 &lcd)
+{
+ // draw the elements in the LCD buffer
+ // pitch
+ lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
+ lcd.drawLine(WIDTH/2,0,WIDTH/2,HEIGHT-1,2);
+ lcd.drawRect(0,0,84,24,FILL_BLACK);
+ //lcd.drawRect(0,0,84,24,FILL_BLACK);
+ //score
+ print_scores(lcd);
+ // boards
+ _p1.draw(lcd);
+ _p2.draw(lcd);
+ // ball
+ _bullet.draw(lcd);
+}
+
+void Touch::update(Gamepad &pad,N5110 &lcd)
+{
+ check_goal(pad);
+ // important to update boards and ball before checking collisions so can
+ // correct for it before updating the display
+ _p1.update(_d,_mag,lcd);
+ //_p2.update(_d,_mag);
+ _bullet.update(lcd);
+
+ check_wall_collision(pad);
+ check_Board_collisions(pad,lcd);
+}
+
+void Touch::check_wall_collision(Gamepad &pad)
+{
+ // read current ball attributes
+ Vector2D bullet_pos = _bullet.get_pos();
+ Vector2D bullet_velocity = _bullet.get_velocity();
+
+ // check if hit top wall
+ if (bullet_pos.y <= 1) { // 1 due to 1 pixel boundary
+ bullet_pos.y = 1; // bounce off ceiling without going off screen
+ bullet_velocity.y = -bullet_velocity.y;
+ // audio feedback
+ pad.tone(750.0,0.1);
+ }
+ // check if hit bottom wall
+ else if (bullet_pos.y + _bullet_size >= (HEIGHT-1) ) { // bottom pixel is 47
+ // hit bottom
+ bullet_pos.y = (HEIGHT-1) - _bullet_size; // stops ball going off screen
+ bullet_velocity.y = -bullet_velocity.y;
+ // audio feedback
+ pad.tone(750.0,0.1);
+ }
+
+ // update ball parameters
+ _bullet.set_velocity(bullet_velocity);
+ _bullet.set_pos(bullet_pos);
+}
+
+void Touch::check_Board_collisions(Gamepad &pad,N5110 &lcd)
+{
+ // read current ball attributes
+ Vector2D bullet_pos = _bullet.get_pos();
+ Vector2D bullet_velocity = _bullet.get_velocity();
+
+ // check p1 first
+ Vector2D p1_pos = _p1.get_pos();
+ Vector2D p2_pos = _p2.get_pos();
+ // see if ball has hit the board by checking for overlaps
+ //lcd.drawRect(0,0,84,24,FILL_BLACK);
+ if (
+ (bullet_pos.y >= p1_pos.y) && //top
+ (bullet_pos.y <= p1_pos.y + _Board_height) && //bottom
+ (bullet_pos.x >= _p1x) && //left
+ (bullet_pos.x <= _p1x + _Board_width) //right
+ ){
+
+ // if it has, fix position and reflect x velocity
+ bullet_pos.x = _p1x + _Board_width;
+ bullet_velocity.x = -bullet_velocity.x;
+ // audio feedback
+ pad.tone(1000.0,0.1);
+
+ }
+ if((bullet_pos.y >= 0)&&(bullet_pos.y <= 24))
+ {
+ lcd.drawRect(bullet_pos.x,bullet_pos.y-4,4,4,FILL_TRANSPARENT);
+ bullet_pos.y = bullet_pos.y + _Board_width;
+ bullet_velocity.y = -bullet_velocity.y;
+ }
+ // check p2 next
+ /* Vector2D p2_pos = _p2.get_pos();
+
+ // see if ball has hit the board by checking for overlaps
+ if (
+ (ball_pos.y >= p2_pos.y) && //top
+ (ball_pos.y <= p2_pos.y + _Board_height) && //bottom
+ (ball_pos.x + _bullet_size >= _p2x) && //left
+ (ball_pos.x + _bullet_size <= _p2x + _Board_width) //right
+ ) {
+ // if it has, fix position and reflect x velocity
+ ball_pos.x = _p2x - _bullet_size;
+ ball_velocity.x = -ball_velocity.x;
+ // audio feedback
+ pad.tone(1000.0,0.1);
+ }*/
+
+ // write new attributes
+ _bullet.set_velocity(bullet_velocity);
+ _bullet.set_pos(bullet_pos);
+}
+
+void Touch::check_goal(Gamepad &pad)
+{
+ Vector2D bullet_pos = _bullet.get_pos();
+ // P2 has scored
+ if (bullet_pos.x + _bullet_size < 0) {
+ _p2.add_score();
+ _bullet.init(_p1x,_bullet_size,_speed,_Board_height);
+ pad.tone(1500.0,0.5);
+ pad.leds_on();
+ wait(0.5);
+ pad.leds_off();
+ }
+
+ // P1 has scored
+ if (bullet_pos.x > WIDTH) {
+ _p1.add_score();
+ _bullet.init(_p1x,_bullet_size,_speed,_Board_height);
+ pad.tone(1500.0,0.5);
+ pad.leds_on();
+ wait(0.5);
+ pad.leds_off();
+ }
+}
+
+void Touch::print_scores(N5110 &lcd)
+{
+ // get scores from boards
+ int p1_score = _p1.get_score();
+ int p2_score = _p2.get_score();
+
+ // print to LCD i
+ char buffer1[14];
+ sprintf(buffer1,"%2d",p1_score);
+ lcd.printString(buffer1,WIDTH/2 - 20,1); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits
+ char buffer2[14];
+ sprintf(buffer2,"%2d",p2_score);
+ lcd.printString(buffer2,WIDTH/2 + 4,1);
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Touch/Touch.h Wed May 27 21:13:59 2020 +0000
@@ -0,0 +1,51 @@
+#ifndef TOUCH_H
+#define TOUCH_H
+
+#include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+#include "Bullet.h"
+#include "Board.h"
+
+// gap from edge of screen
+#define GAP 2
+
+class Touch
+{
+
+public:
+ Touch();
+ ~Touch();
+
+ void init(int Board_width,int Board_height,int bullet_size,int speed,N5110 &lcd);
+ void read_input(Gamepad &pad);
+ void update(Gamepad &pad,N5110 &lcd);
+ void draw(N5110 &lcd);
+
+private:
+
+ void check_wall_collision(Gamepad &pad);
+ void check_Board_collisions(Gamepad &pad,N5110 &lcd);
+ void check_goal(Gamepad &pad);
+ void print_scores(N5110 &lcd);
+
+ Board _p1;
+ Board _p2;
+
+ int _Board_width;
+ int _Board_height;
+ int _bullet_size;
+ int _speed;
+
+ // x positions of the Boards
+ int _p1x;
+ int _p2x;
+ int _p1y;
+ Bullet _bullet;
+
+ Direction _d;
+ float _mag;
+
+};
+
+#endif
\ No newline at end of file
--- a/main.cpp Sat May 23 18:12:03 2020 +0000
+++ b/main.cpp Wed May 27 21:13:59 2020 +0000
@@ -1,27 +1,93 @@
-/*
-ELEC2645 Embedded Systems Project
-School of Electronic & Electrical Engineering
-University of Leeds
-2019/20
-
-Name:Chen Zirui
-Username:el18zc
-Student ID Number:201235448
-Date:5.03.2020
-*/
-
-// includes
+///////// pre-processor directives ////////
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
+#include "Touch.h"
+#ifdef WITH_TESTING
+#include "test.h"
+#endif
+#define PADDLE_WIDTH 2
+#define PADDLE_HEIGHT 8
+#define BALL_SIZE 2
+#define BALL_SPEED 3
-// objects
+/////////////// structs /////////////////
+struct UserInput {
+ Direction d;
+ float mag;
+};
+/////////////// objects ///////////////
+N5110 lcd;
Gamepad pad;
-N5110 lcd;
+Touch touch;
+///////////// prototypes ///////////////
+void init();
+void update_game(UserInput input);
+void render();
+void welcome();
+
+///////////// functions ////////////////
int main()
{
-
+#ifdef WITH_TESTING
+ int number_of_failures = run_all_tests();
+
+ if(number_of_failures > 0) return number_of_failures;
+#endif
+ int fps = 6; // frames per second
+ init(); // initialise and then display welcome screen...
+ welcome(); // waiting for the user to start;
+ render(); // first draw the initial frame
+ wait(1.0f/fps); // and wait for one frame period
+
+ //lcd.drawRect(0,0,84,24,FILL_BLACK);
+ // game loop - read input, update the game state and render the display
+ while (1) {
+ touch.read_input(pad);
+ touch.update(pad,lcd);
+ render();
+ //lcd.drawRect(0,0,84,24,FILL_BLACK);
+ wait(1.0f/fps);
+ }
}
+// initialies all classes and libraries
+void init()
+{
+ // need to initialise LCD and Gamepad
+ lcd.init();
+ pad.init();
+
+ // initialise the game with correct ball and paddle sizes
+ pong.init(PADDLE_WIDTH,PADDLE_HEIGHT,BALL_SIZE,BALL_SPEED,lcd);
+
+}
+
+// this function draws each frame on the LCD
+void render()
+{
+ // clear screen, re-draw and refresh
+ lcd.clear();
+ touch.draw(lcd);
+ lcd.refresh();
+}
+
+// simple splash screen displayed on start-up
+void welcome() {
+
+ lcd.printString(" touch! ",0,1);
+ lcd.printString(" Press Start ",0,4);
+ lcd.refresh();
+
+ // wait flashing LEDs until start button is pressed
+ while ( pad.start_pressed() == false) {
+ lcd.setContrast( pad.read_pot1());
+ pad.leds_on();
+ wait(0.1);
+ pad.leds_off();
+ wait(0.1);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test.h Wed May 27 21:13:59 2020 +0000
@@ -0,0 +1,43 @@
+#ifndef TESTS_H
+#define TESTS_H
+
+#include "Bullet_test.h"
+
+/**
+ * @brief Run all the tests for this program
+ *
+ * @returns The number of tests that failed
+ */
+int run_all_tests()
+{
+ int n_tests_failed = 0; // A log of the number of tests that have failed
+
+ // Run the Ball_test_movement test
+ printf("Testing Ball_test_movement...\n");
+ bool this_test_passed = Ball_test_movement();
+
+ // Print out the result of this test
+ if (this_test_passed) {
+ printf("...Passed!\n");
+ }
+ else {
+ printf("...FAILED!\n");
+ ++n_tests_failed; // Increment number of failures
+ }
+
+ // Repeat the above for each testing function...
+ // ...
+ // ...
+
+ // Finish by printing a summary of the tests
+ if (n_tests_failed > 0) {
+ printf("%d tests FAILED!\n", n_tests_failed);
+ }
+ else {
+ printf("All tests passed!\n");
+ }
+
+ return n_tests_failed;
+}
+
+#endif
\ No newline at end of file