Advertisement
Guest User

catch

a guest
Oct 16th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 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. //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. LEDMAT_ROW1_PIO, LEDMAT_ROW2_PIO, LEDMAT_ROW3_PIO, LEDMAT_ROW4_PIO,
  14. LEDMAT_ROW5_PIO, LEDMAT_ROW6_PIO, LEDMAT_ROW7_PIO
  15. };
  16. static pio_t ledmat_cols[] = {
  17. LEDMAT_COL1_PIO, LEDMAT_COL2_PIO, LEDMAT_COL3_PIO,
  18. LEDMAT_COL4_PIO, LEDMAT_COL5_PIO
  19. };
  20.  
  21. static void ledmat_pixel_set (int col, int row, bool state)
  22. {
  23. if (state) {
  24. pio_output_low (ledmat_rows[row]);
  25. pio_output_low (ledmat_cols[col]);
  26. } else {
  27. pio_output_high (ledmat_rows[row]);
  28. pio_output_high (ledmat_cols[col]);
  29. }
  30. }
  31.  
  32. static void ledmat_init (void)
  33. {
  34. uint8_t row;
  35. uint8_t col;
  36.  
  37. //initialise each row
  38. for (row = 0; row < 7; row++) {
  39. pio_config_set (ledmat_rows[row], PIO_OUTPUT_HIGH);
  40. pio_output_high (ledmat_rows[row]);
  41. }
  42.  
  43. //initialise each column
  44. for (col = 0; col < 5; col++) {
  45. pio_config_set (ledmat_cols[col], PIO_OUTPUT_HIGH);
  46. pio_output_high (ledmat_cols[col]);
  47. }
  48. }
  49.  
  50.  
  51. uint8_t ballPos(void)
  52. {
  53. ir_serial_init();
  54. uint8_t data;
  55. while(1) {
  56. pacer_wait();
  57. ir_serial_ret_t ret;
  58. ret = ir_serial_receive (&data);
  59. if (ret == IR_SERIAL_OK) {
  60. return data = 3 - data;
  61. // matching the ball to the correct row
  62. //return data;
  63. }
  64. }
  65. }
  66.  
  67.  
  68.  
  69.  
  70. void catch (uint8_t playerPosition)
  71. {
  72. pacer_init(PACER_RATE);
  73. ledmat_init();
  74.  
  75. uint8_t row = playerPosition;
  76. int col = 0; //was 4
  77. //ledmat_pixel_set (4, playerPosition, 1);
  78. uint64_t tick = 0;
  79. while (1) {
  80. pacer_wait ();
  81. ledmat_pixel_set (col, row, 0);
  82. //ledmat_pixel_set (0, playerPosition, 1); //col input was 4
  83. //was decrement the column
  84. col++;
  85. while(1) {
  86. pacer_wait();
  87. ledmat_pixel_set (col, row, 1);
  88. tick++;
  89. //keep the led on for some time using ticks
  90. if (tick >= 50) {
  91. tick = 0;
  92. break;
  93. }
  94. }
  95. //in the case that col = 0, hold it for some time using ticks
  96. //then turn it off and return to main
  97. if (col == 4) {
  98. while(1) {
  99. pacer_wait();
  100. ledmat_pixel_set (col, row, 1);
  101. tick++;
  102. if (tick >= 50) {
  103. tick = 0;
  104. break;
  105. }
  106. }
  107. ledmat_pixel_set (col, row, 0);
  108. navswitch_update();
  109. return;
  110. }
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement