Advertisement
Guest User

throwBall

a guest
Oct 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. #include "system.h"
  2. #include "pacer.h"
  3. #include "pio.h"
  4. #include "navswitch.h"
  5.  
  6.  
  7. //Define pace in Hz
  8. #define PACER_RATE 1000
  9.  
  10.  
  11. //Define PIO pins and LED Mat rows and columns
  12. static pio_t ledmat_rows[] =
  13. {
  14. LEDMAT_ROW1_PIO, LEDMAT_ROW2_PIO, LEDMAT_ROW3_PIO, LEDMAT_ROW4_PIO,
  15. LEDMAT_ROW5_PIO, LEDMAT_ROW6_PIO, LEDMAT_ROW7_PIO
  16. };
  17. static pio_t ledmat_cols[] =
  18. {
  19. LEDMAT_COL1_PIO, LEDMAT_COL2_PIO, LEDMAT_COL3_PIO,
  20. LEDMAT_COL4_PIO, LEDMAT_COL5_PIO
  21. };
  22.  
  23. static void ledmat_pixel_set (int col, int row, bool state)
  24. {
  25. if (state)
  26. {
  27. pio_output_low (ledmat_rows[row]);
  28. pio_output_low (ledmat_cols[col]);
  29. }
  30. else
  31. {
  32. pio_output_high (ledmat_rows[row]);
  33. pio_output_high (ledmat_cols[col]);
  34. }
  35. }
  36.  
  37. static void ledmat_init (void)
  38. {
  39. uint8_t row;
  40. uint8_t col;
  41.  
  42. //initialise each row
  43. for (row = 0; row < 7; row++)
  44. {
  45. pio_config_set (ledmat_rows[row], PIO_OUTPUT_HIGH);
  46. pio_output_high (ledmat_rows[row]);
  47. }
  48.  
  49. //initialise each column
  50. for (col = 0; col < 5; col++)
  51. {
  52. pio_config_set (ledmat_cols[col], PIO_OUTPUT_HIGH);
  53. pio_output_high (ledmat_cols[col]);
  54. }
  55. }
  56.  
  57. void throw (uint8_t playerPosition) {
  58. pacer_init(PACER_RATE);
  59. ledmat_init();
  60. int row = playerPosition;
  61. int col = 4;
  62. uint64_t tick = 0;
  63. while (1)
  64. {
  65. pacer_wait ();
  66.  
  67. ledmat_pixel_set (col, row, 0);
  68. //decrement the column
  69. col--;
  70. while(1) {
  71. pacer_wait();
  72. ledmat_pixel_set (col, row, 1);
  73. tick++;
  74. //keep the led on for some time using ticks
  75. if (tick >= 100) {
  76. tick = 0;
  77. break;
  78. }
  79. }
  80. //in the case that col = 0, hold it for some time using ticks
  81. //then turn it off and return to main
  82. if (col == 0) {
  83. while(1) {
  84. pacer_wait();
  85. ledmat_pixel_set (col, row, 1);
  86. tick++;
  87. if (tick >= 100) {
  88. tick = 0;
  89. break;
  90. }
  91. }
  92. ledmat_pixel_set (col, row, 0);
  93. navswitch_update();
  94. return;
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement