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