-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <ADCTouchSensor.h> | ||
|
||
// | ||
// This requires an stm32f1 board compatible with the no-grounding-pin feature of ADCTouchSensor, | ||
// and this branch of the stm32f1 core: https://github.com/arpruss/Arduino_STM32/tree/addMidiHID | ||
// | ||
|
||
#define LED_BUILTIN PB12 // change to match your board | ||
|
||
#define NUM_PINS 10 | ||
unsigned pins[NUM_PINS] = {PA0,PA1,PA2,PA3,PA4,PA5,PA6,PA7,PA8,PA9}; | ||
unsigned keys[NUM_PINS] = {' ',KEY_UP_ARROW,KEY_LEFT_ARROW,KEY_DOWN_ARROW,KEY_RIGHT_ARROW,'w','a','s','d','f'}; // Makey-Makey also has 'g' and CLICK, but we don't have enough ADC channels | ||
unsigned prev[NUM_PINS]; | ||
|
||
ADCTouchSensor* sensors[NUM_PINS]; | ||
|
||
void setup() | ||
{ | ||
pinMode(LED_BUILTIN, OUTPUT); | ||
digitalWrite(LED_BUILTIN, 0); | ||
|
||
for (int i=0; i<NUM_PINS; i++) { | ||
sensors[i] = new ADCTouchSensor(pins[i]); | ||
sensors[i]->begin(); | ||
prev[i] = 0; | ||
} | ||
|
||
digitalWrite(LED_BUILTIN, 1); | ||
} | ||
|
||
void loop() | ||
{ | ||
uint8_t pressed = 0; | ||
|
||
for (int i=0; i<NUM_PINS; i++) { | ||
if (sensors[i]->read() > 25) { | ||
pressed = 1; | ||
if(!prev[i]) { | ||
Keyboard.press(keys[i]); | ||
prev[i] = 1; | ||
} | ||
} | ||
else { | ||
if(prev[i]) { | ||
Keyboard.release(keys[i]); | ||
prev[i] = 0; | ||
} | ||
} | ||
} | ||
|
||
digitalWrite(LED_BUILTIN, !pressed); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=ADCTouchSensor | ||
version=0.0.4 | ||
version=0.0.5 | ||
author=Alexander Pruss | ||
maintainer=arpruss <[email protected]> | ||
sentence=Create Touch Sensors with a single analog pin without external hardware | ||
|