Display an animated Sinuswave using GREY_SCALE_MODE for the display. Well - its my forst program.
main.cpp@0:54e78c24b373, 2017-08-22 (annotated)
- Committer:
- DieOma
- Date:
- Tue Aug 22 09:37:33 2017 +0000
- Revision:
- 0:54e78c24b373
Just optimized
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DieOma | 0:54e78c24b373 | 1 | |
DieOma | 0:54e78c24b373 | 2 | #include "MicroBit.h" |
DieOma | 0:54e78c24b373 | 3 | #include "mbed.h" |
DieOma | 0:54e78c24b373 | 4 | #include <math.h> /* sin */ |
DieOma | 0:54e78c24b373 | 5 | |
DieOma | 0:54e78c24b373 | 6 | |
DieOma | 0:54e78c24b373 | 7 | //A little Animation for using GREY_SCALE_MODE |
DieOma | 0:54e78c24b373 | 8 | MicroBit uBit; |
DieOma | 0:54e78c24b373 | 9 | MicroBitImage map(5,5); |
DieOma | 0:54e78c24b373 | 10 | |
DieOma | 0:54e78c24b373 | 11 | int main() { |
DieOma | 0:54e78c24b373 | 12 | uBit.init(); |
DieOma | 0:54e78c24b373 | 13 | uBit.display.print(map); |
DieOma | 0:54e78c24b373 | 14 | uBit.display.setDisplayMode(DISPLAY_MODE_GREYSCALE); |
DieOma | 0:54e78c24b373 | 15 | int value = 250; |
DieOma | 0:54e78c24b373 | 16 | int k = 0; |
DieOma | 0:54e78c24b373 | 17 | while (1) { |
DieOma | 0:54e78c24b373 | 18 | for(int i = 0; i<5;i++){ |
DieOma | 0:54e78c24b373 | 19 | for(int j = 0; j < 5; j++){ |
DieOma | 0:54e78c24b373 | 20 | value = (125 *(1 + sin((i+k) * PI / 10))); |
DieOma | 0:54e78c24b373 | 21 | uBit.display.image.setPixelValue(i,j, value); } |
DieOma | 0:54e78c24b373 | 22 | |
DieOma | 0:54e78c24b373 | 23 | }; |
DieOma | 0:54e78c24b373 | 24 | k++; |
DieOma | 0:54e78c24b373 | 25 | uBit.sleep(100); |
DieOma | 0:54e78c24b373 | 26 | |
DieOma | 0:54e78c24b373 | 27 | |
DieOma | 0:54e78c24b373 | 28 | }; |
DieOma | 0:54e78c24b373 | 29 | |
DieOma | 0:54e78c24b373 | 30 | } |