Advertisement
Guest User

throwBall

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