├── LICENSE ├── CHANGELOG ├── README └── CNCRouterController.ino /LICENSE: -------------------------------------------------------------------------------- 1 | This code should be considered public domain. -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | 2 | 2012-02-06 Pete Prodoehl 3 | 4 | * Initial release 5 | 6 | 7 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | Code for a Teensy, using Teensyduino with the Arduino IDE, to control Mach3, and the CNC Router at the Milwaukee Makerspace. 3 | 4 | 5 | For background on the CNC Router Controller see: 6 | 7 | http://wiki.milwaukeemakerspace.org/projects/cncroutercontrollerbox 8 | 9 | 10 | See also: 11 | 12 | http://www.pjrc.com/teensy/usb_keyboard.html 13 | 14 | 15 | Grab the Bounce library from here: 16 | 17 | http://www.pjrc.com/teensy/td_libs_Bounce.html 18 | 19 | 20 | 21 | Pete Prodoehl 22 | pete@rasterweb.net 23 | http://rasterweb.net/raster/ 24 | Twitter: @raster 25 | 26 | -------------------------------------------------------------------------------- /CNCRouterController.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * CNCRouterController.pde 3 | * 4 | * You must select Keyboard from the "Tools > USB Type" menu 5 | * 6 | * Download and install the Bounce library: http://www.pjrc.com/teensy/td_libs_Bounce.html 7 | * 8 | */ 9 | 10 | #include 11 | 12 | // Create Bounce objects for each button. The Bounce object 13 | // automatically deals with contact chatter or "bounce", and 14 | // it makes detecting changes very simple. 15 | Bounce button0 = Bounce(0, 10); 16 | Bounce button1 = Bounce(1, 10); // 10 = 10 ms debounce time 17 | Bounce button2 = Bounce(2, 10); // which is appropriate for 18 | Bounce button3 = Bounce(3, 10); // most mechanical pushbuttons 19 | Bounce button4 = Bounce(4, 10); 20 | Bounce button5 = Bounce(5, 10); // if a button is too "sensitive" 21 | Bounce button6 = Bounce(6, 10); // to rapid touch, you can 22 | Bounce button7 = Bounce(7, 10); // increase this time. 23 | Bounce button8 = Bounce(8, 10); 24 | Bounce button9 = Bounce(9, 10); 25 | 26 | 27 | void setup() { 28 | // Configure the pins for input mode with pullup resistors. 29 | // The pushbuttons connect from each pin to ground. When 30 | // the button is pressed, the pin reads LOW because the button 31 | // shorts it to ground. When released, the pin reads HIGH 32 | // because the pullup resistor connects to +5 volts inside 33 | // the chip. LOW for "on", and HIGH for "off" may seem 34 | // backwards, but using the on-chip pullup resistors is very 35 | // convenient. The scheme is called "active low", and it's 36 | // very commonly used in electronics... so much that the chip 37 | // has built-in pullup resistors! 38 | pinMode(0, INPUT_PULLUP); 39 | pinMode(1, INPUT_PULLUP); 40 | pinMode(2, INPUT_PULLUP); 41 | pinMode(3, INPUT_PULLUP); 42 | pinMode(4, INPUT_PULLUP); 43 | pinMode(5, INPUT_PULLUP); 44 | pinMode(6, INPUT_PULLUP); 45 | pinMode(7, INPUT_PULLUP); 46 | pinMode(8, INPUT_PULLUP); 47 | pinMode(9, INPUT_PULLUP); 48 | 49 | 50 | pinMode(20, INPUT_PULLUP); 51 | 52 | } 53 | 54 | void loop() { 55 | // Update all the buttons. There should not be any long 56 | // delays in loop(), so this runs repetitively at a rate 57 | // faster than the buttons could be pressed and released. 58 | button0.update(); 59 | button1.update(); 60 | button2.update(); 61 | button3.update(); 62 | button4.update(); 63 | button5.update(); 64 | button6.update(); 65 | button7.update(); 66 | button8.update(); 67 | button9.update(); 68 | 69 | // Check each button for "falling" edge. 70 | // Type a message on the Keyboard when each button presses 71 | // Update the Joystick buttons only upon changes. 72 | // falling = high (not pressed - voltage from pullup resistor) 73 | // to low (pressed - button connects pin to ground) 74 | if (button0.fallingEdge()) { 75 | checkctrl(); 76 | Keyboard.set_key1(KEY_RIGHT); 77 | Keyboard.send_now(); 78 | } 79 | if (button0.risingEdge()) { 80 | checkctrl(); 81 | releasekey(); 82 | } 83 | 84 | if (button1.fallingEdge()) { 85 | checkctrl(); 86 | Keyboard.set_key1(KEY_LEFT); 87 | Keyboard.send_now(); 88 | } 89 | if (button1.risingEdge()) { 90 | checkctrl(); 91 | releasekey(); 92 | } 93 | 94 | if (button2.fallingEdge()) { 95 | checkctrl(); 96 | Keyboard.set_key1(KEY_UP); 97 | Keyboard.send_now(); 98 | } 99 | if (button2.risingEdge()) { 100 | checkctrl(); 101 | releasekey(); 102 | } 103 | 104 | if (button3.fallingEdge()) { 105 | checkctrl(); 106 | Keyboard.set_key1(KEY_DOWN); 107 | Keyboard.send_now(); 108 | } 109 | if (button3.risingEdge()) { 110 | checkctrl(); 111 | releasekey(); 112 | } 113 | 114 | if (button4.fallingEdge()) { 115 | checkctrl(); 116 | Keyboard.set_key1(KEY_PAGE_UP); 117 | Keyboard.send_now(); 118 | } 119 | if (button4.risingEdge()) { 120 | checkctrl(); 121 | releasekey(); 122 | } 123 | 124 | if (button5.fallingEdge()) { 125 | checkctrl(); 126 | Keyboard.set_key1(KEY_PAGE_DOWN); 127 | Keyboard.send_now(); 128 | } 129 | if (button5.risingEdge()) { 130 | checkctrl(); 131 | releasekey(); 132 | } 133 | 134 | if (button6.fallingEdge()) { 135 | Keyboard.set_modifier(MODIFIERKEY_ALT); 136 | Keyboard.set_key1(KEY_R); 137 | Keyboard.send_now(); 138 | releasekey(); 139 | } 140 | if (button6.risingEdge()) { 141 | releasekey(); 142 | } 143 | 144 | if (button7.fallingEdge()) { 145 | Keyboard.set_modifier(MODIFIERKEY_ALT); 146 | Keyboard.set_key1(KEY_S); 147 | Keyboard.send_now(); 148 | releasekey(); 149 | } 150 | if (button7.risingEdge()) { 151 | releasekey(); 152 | } 153 | 154 | 155 | } 156 | 157 | void checkctrl() { 158 | if (digitalRead(20) == HIGH) { 159 | Keyboard.set_modifier(0); 160 | } 161 | if (digitalRead(20) == LOW) { 162 | Keyboard.set_modifier(MODIFIERKEY_CTRL); 163 | // MODIFIERKEY_SHIFT <-- set to this for testing 164 | } 165 | } 166 | 167 | 168 | void releasekey() { 169 | Keyboard.set_key1(0); 170 | Keyboard.send_now(); 171 | } 172 | 173 | 174 | // 175 | 176 | --------------------------------------------------------------------------------