sources and files for the bombatuino project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.3 KiB

  1. #include <Wire.h>
  2. #include <SoftwareSerial.h>
  3. #define IOPOLA 0x02
  4. #define GPPUA 0x12
  5. #define BIT_IS_SET(i, bits) (1 << i & bits)
  6. SoftwareSerial MIDI(10,11);
  7. boolean button[8];
  8. void setup()
  9. {
  10. //printing baudrate
  11. Serial.begin(9600);
  12. MIDI.begin(31250);
  13. Wire.begin();
  14. Wire.beginTransmission(0x20);
  15. Wire.write(0x12); // set MCP23017 memory pointer to GPIOB address
  16. Wire.write(0xFF); //PULLUP
  17. Wire.endTransmission();
  18. }
  19. void loop()
  20. {
  21. Wire.beginTransmission(0x20);
  22. Wire.write(0x12); // set MCP23017 memory pointer to GPIOB address
  23. Wire.endTransmission();
  24. Wire.requestFrom(0x20, 1); // request one byte of data from MCP20317
  25. int inputs = Wire.read();
  26. delayMicroseconds(10);
  27. //check if button is pressed
  28. int i;
  29. for(i=0;i<8;i++) {
  30. if (BIT_IS_SET(i,inputs)) {
  31. if(!button[i]) {
  32. button[i] = true;
  33. midiSignal(144,60+i,115);
  34. }
  35. } else {
  36. if(button[i]) {
  37. button[i] = false;
  38. midiSignal(128,60+i,0);
  39. }
  40. }
  41. }
  42. }
  43. //send MIDI signal through softwareserial
  44. void midiSignal(byte b1, byte b2, byte b3) {
  45. Serial.print(b1);
  46. Serial.print(" ");
  47. Serial.print(b2);
  48. Serial.print(" ");
  49. Serial.print(b3);
  50. Serial.print(" ");
  51. Serial.println();
  52. MIDI.write(b1);
  53. MIDI.write(b2);
  54. MIDI.write(b2);
  55. }