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
N5110/Bitmap.h@46:824ec81ff578, 2019-05-08 (annotated)
- Committer:
 - el17cd
 - Date:
 - Wed May 08 18:17:59 2019 +0000
 - Revision:
 - 46:824ec81ff578
 - Parent:
 - 0:efb5eec6b8ea
 
Potentiometer now changes screen contrast for use on other devices.; Final Submission.; I have read and agreed with the Statement of Academic Integrity.
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| el17cd | 0:efb5eec6b8ea | 1 | #ifndef BITMAP_H | 
| el17cd | 0:efb5eec6b8ea | 2 | #define BITMAP_H | 
| el17cd | 0:efb5eec6b8ea | 3 | |
| el17cd | 0:efb5eec6b8ea | 4 | #include <vector> | 
| el17cd | 0:efb5eec6b8ea | 5 | |
| el17cd | 0:efb5eec6b8ea | 6 | // Forward declarations | 
| el17cd | 0:efb5eec6b8ea | 7 | class N5110; | 
| el17cd | 0:efb5eec6b8ea | 8 | |
| el17cd | 0:efb5eec6b8ea | 9 | /** | 
| el17cd | 0:efb5eec6b8ea | 10 | * @brief A black & white bitmap that can be rendered on an N5110 screen | 
| el17cd | 0:efb5eec6b8ea | 11 | * @author Alex Valavanis <a.valavanis@leeds.ac.uk> | 
| el17cd | 0:efb5eec6b8ea | 12 | * | 
| el17cd | 0:efb5eec6b8ea | 13 | * @code | 
| el17cd | 0:efb5eec6b8ea | 14 | // First declare the pixel map data using '1' for black, | 
| el17cd | 0:efb5eec6b8ea | 15 | // or '0' for white pixels | 
| el17cd | 0:efb5eec6b8ea | 16 | static int sprite_data[] = { | 
| el17cd | 0:efb5eec6b8ea | 17 | 0,0,1,0,0, | 
| el17cd | 0:efb5eec6b8ea | 18 | 0,1,1,1,0, | 
| el17cd | 0:efb5eec6b8ea | 19 | 0,0,1,0,0, | 
| el17cd | 0:efb5eec6b8ea | 20 | 0,1,1,1,0, | 
| el17cd | 0:efb5eec6b8ea | 21 | 1,1,1,1,1, | 
| el17cd | 0:efb5eec6b8ea | 22 | 1,1,1,1,1, | 
| el17cd | 0:efb5eec6b8ea | 23 | 1,1,0,1,1, | 
| el17cd | 0:efb5eec6b8ea | 24 | 1,1,0,1,1 | 
| el17cd | 0:efb5eec6b8ea | 25 | }; | 
| el17cd | 0:efb5eec6b8ea | 26 | |
| el17cd | 0:efb5eec6b8ea | 27 | // Instantiate the Bitmap object using the data above | 
| el17cd | 0:efb5eec6b8ea | 28 | Bitmap sprite(sprite_data, 8, 5); // Specify rows and columns in sprite | 
| el17cd | 0:efb5eec6b8ea | 29 | |
| el17cd | 0:efb5eec6b8ea | 30 | // We can render the bitmap wherever we want on the screen | 
| el17cd | 0:efb5eec6b8ea | 31 | sprite.render(lcd, 20, 6); // x and y locations for rendering | 
| el17cd | 0:efb5eec6b8ea | 32 | sprite.render(lcd, 30, 10); | 
| el17cd | 0:efb5eec6b8ea | 33 | |
| el17cd | 0:efb5eec6b8ea | 34 | // We can also print its values to the terminal | 
| el17cd | 0:efb5eec6b8ea | 35 | sprite.print(); | 
| el17cd | 0:efb5eec6b8ea | 36 | * @endcode | 
| el17cd | 0:efb5eec6b8ea | 37 | */ | 
| el17cd | 0:efb5eec6b8ea | 38 | class Bitmap | 
| el17cd | 0:efb5eec6b8ea | 39 | { | 
| el17cd | 0:efb5eec6b8ea | 40 | private: | 
| el17cd | 0:efb5eec6b8ea | 41 | /** | 
| el17cd | 0:efb5eec6b8ea | 42 | * @brief The contents of the drawing, with pixels stored in row-major order | 
| el17cd | 0:efb5eec6b8ea | 43 | * @details '1' represents a black pixel; '0' represents white | 
| el17cd | 0:efb5eec6b8ea | 44 | */ | 
| el17cd | 0:efb5eec6b8ea | 45 | std::vector<int> _contents; | 
| el17cd | 0:efb5eec6b8ea | 46 | |
| el17cd | 0:efb5eec6b8ea | 47 | unsigned int _height; ///< The height of the drawing in pixels | 
| el17cd | 0:efb5eec6b8ea | 48 | unsigned int _width; ///< The width of the drawing in pixels | 
| el17cd | 0:efb5eec6b8ea | 49 | |
| el17cd | 0:efb5eec6b8ea | 50 | public: | 
| el17cd | 0:efb5eec6b8ea | 51 | Bitmap(int const *contents, | 
| el17cd | 0:efb5eec6b8ea | 52 | unsigned int const height, | 
| el17cd | 0:efb5eec6b8ea | 53 | unsigned int const width); | 
| el17cd | 0:efb5eec6b8ea | 54 | |
| el17cd | 0:efb5eec6b8ea | 55 | int get_pixel(unsigned int const row, | 
| el17cd | 0:efb5eec6b8ea | 56 | unsigned int const column) const; | 
| el17cd | 0:efb5eec6b8ea | 57 | |
| el17cd | 0:efb5eec6b8ea | 58 | void print() const; | 
| el17cd | 0:efb5eec6b8ea | 59 | |
| el17cd | 0:efb5eec6b8ea | 60 | void render(N5110 &lcd, | 
| el17cd | 0:efb5eec6b8ea | 61 | unsigned int const x0, | 
| el17cd | 0:efb5eec6b8ea | 62 | unsigned int const y0) const; | 
| el17cd | 0:efb5eec6b8ea | 63 | }; | 
| el17cd | 0:efb5eec6b8ea | 64 | |
| el17cd | 0:efb5eec6b8ea | 65 | #endif // BITMAP_H |