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.

143 lines
2.7 KiB

5 years ago
  1. /*
  2. * Computer Switchboard
  3. *
  4. * Because interfacing with computers should be fun
  5. * and a keyboard is not enough.
  6. *
  7. * Let's turn a computer into an airplane (interface wise).
  8. *
  9. *
  10. *
  11. * MINIMAL:
  12. * I only need the button to shutdown the computer. No rotary or 7seg.
  13. */
  14. //todo: debounce, see neotimer
  15. //makes serial slower so it can be read
  16. #define DEBUGMODE 0
  17. #include <avr/io.h>
  18. #include <avr/interrupt.h>
  19. //switch
  20. // digital pin 9 has a pushbutton attached to it. Give it a name:
  21. int pushButton = 9;
  22. // Example showing use of the MD_KeySwitch library
  23. //
  24. // Momentary switch
  25. //
  26. // Prints the switch value on the Serial Monitor
  27. // Allows setting of options to see theior effect (see setup())
  28. //
  29. #include <MD_KeySwitch.h>
  30. // This is just an average debounce -steak
  31. // what i need is a way to actually, not register if I don't pick up the depressed button
  32. // but good enough for now
  33. const uint8_t SWITCH_PIN = 9; // switch connected to this pin
  34. const uint8_t SWITCH_ACTIVE = LOW; // digital signal when switch is pressed 'on'
  35. MD_KeySwitch S(SWITCH_PIN, SWITCH_ACTIVE);
  36. void setup() {
  37. // initialize I/O pins
  38. Serial.begin(9600);
  39. Serial.println("GnuxSwitcher");
  40. pinMode(pushButton, INPUT_PULLUP);
  41. pinMode(LED_BUILTIN, OUTPUT);
  42. S.begin();
  43. //S.enableDoublePress(true);
  44. //S.enableLongPress(true);
  45. /*S.enableRepeat(true);
  46. S.enableRepeatResult(true);*/
  47. }
  48. void loop() {
  49. //BUTTONS
  50. /* int resultb = 0;
  51. resultb = PINB;
  52. delay(100);
  53. if (resultb == 0 ){
  54. decPt = 1;
  55. Serial.print("User Pressed button: ");
  56. Serial.println(segdisp);
  57. }
  58. else{
  59. decPt = 0;
  60. }
  61. */
  62. // too fast, print serial when checking switch only
  63. // Serial.println(resultb,BIN); // noisy, but reads 0 when low.
  64. switch(S.read())
  65. {
  66. case MD_KeySwitch::KS_NULL: /* Serial.println("NULL"); */ break;
  67. case MD_KeySwitch::KS_PRESS:
  68. //Serial.println("\nSINGLE PRESS");
  69. Serial.println("Initiate the Shutdown Procedure Immediately");
  70. digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
  71. delay(1000); // wait for a second
  72. digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
  73. break;
  74. /*
  75. case MD_KeySwitch::KS_DPRESS: Serial.print("\nDOUBLE PRESS");
  76. break;*/
  77. //case MD_KeySwitch::KS_LONGPRESS: Serial.print("\nLONG PRESS");
  78. //break; //this doesn't seem to work at all. - steak
  79. /*
  80. case MD_KeySwitch::KS_RPTPRESS: Serial.print("\nREPEAT PRESS");
  81. break;
  82. */
  83. default: Serial.print("\nUNKNOWN");
  84. break;
  85. }
  86. }