Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. // Drawing faces on button press using template by MIKE SPIVEY
  2. // AARON OMOTOSHO
  3.  
  4. #include "hardware.h"
  5.  
  6. /* delay -- pause for n microseconds */
  7. void delay(unsigned n) {
  8. unsigned t = n << 1;
  9. while (t > 0) {
  10. // 500nsec per iteration at 16MHz
  11. nop(); nop(); nop();
  12. t--;
  13. }
  14. }
  15.  
  16. static const unsigned smile[] = {
  17. 0x3070, 0x59f0, 0x9ae0
  18. };
  19.  
  20. static const unsigned frown[] = {
  21. 0x38f0, 0x59f0, 0x9a80
  22. };
  23.  
  24. static const unsigned spot[] = {
  25. 0x0000, 0x5fb0, 0x0000
  26. };
  27.  
  28. static const unsigned nought[] = {
  29. 0x0000, 0x0000, 0x0000
  30. };
  31.  
  32. /* show -- display three rows of a picture n times */
  33. void show(const unsigned *img, int n) {
  34. while (n-- > 0) {
  35. // Takes 15msec per iteration
  36. for (int p = 0; p < 3; p++) {
  37. GPIO_OUT = img[p];
  38. delay(5000);
  39. }
  40. }
  41. }
  42.  
  43. int a_pressed(void) {
  44. return (GPIO_IN & 0x20000) != 0x20000;
  45. }
  46. int b_pressed(void) {
  47. return (GPIO_IN & 0x4000000) != 0x4000000;
  48. }
  49.  
  50.  
  51. void init(void) {
  52. GPIO_DIR = 0xfff0;
  53. GPIO_PINCNF[BUTTON_A] = 0;
  54. GPIO_PINCNF[BUTTON_B] = 0;
  55.  
  56. while (1) {
  57. if (a_pressed()) {
  58. show(frown, 1);
  59. } else if (b_pressed()){
  60. show(smile, 1);
  61. } else {
  62. show(spot, 10);
  63. show(nought, 10);
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement