Posted By

donfips on 04/17/11


Tagged


Versions (?)

SNES Serial w. Ardiuno


 / Published in: C
 

  1. /*
  2.   SNES buttons via serial
  3.   libs used http://code.google.com/p/nespad/
  4.  
  5. */
  6.  
  7. #include <SNESpad.h>
  8.  
  9. // (strobe/clock/data)
  10. SNESpad nintendo = SNESpad(9,11,8);
  11. int state = 0;
  12.  
  13. void setup() {
  14. Serial.begin(57600);
  15. }
  16.  
  17. void loop() {
  18.  
  19. state = nintendo.buttons();
  20.  
  21. // Serial.println(~state, BIN);
  22.  
  23. switch(state)
  24. {
  25. case 0x01:
  26. Serial.println("SNES_B");
  27. break;
  28.  
  29. case 0x02:
  30. Serial.println("SNES_Y");
  31. break;
  32.  
  33. case 0x04:
  34. Serial.println("SNES_SELECT");
  35. break;
  36.  
  37. case 0x08:
  38. Serial.println("SNES_START");
  39. break;
  40.  
  41. case 0x10:
  42. Serial.println("SNES_UP");
  43. break;
  44.  
  45. case 0x20:
  46. Serial.println("SNES_DOWN");
  47. break;
  48.  
  49. case 0x40:
  50. Serial.println("SNES_LEFT");
  51. break;
  52.  
  53. case 0x80:
  54. Serial.println("SNES_RIGHT");
  55. break;
  56.  
  57. case 0x100:
  58. Serial.println("SNES_A");
  59. break;
  60.  
  61. case 0x200:
  62. Serial.println("SNES_X");
  63. break;
  64.  
  65. case 0x400:
  66. Serial.println("SNES_L");
  67. break;
  68.  
  69. case 0x800:
  70. Serial.println("SNES_R");
  71. break;
  72.  
  73. }
  74.  
  75. delay(100);
  76. }

Report this snippet  

You need to login to post a comment.