Created
October 9, 2017 23:51
-
-
Save witnessmenow/7bdb21589777cac576b35497fa8263b2 to your computer and use it in GitHub Desktop.
Arduino code for a bluetooth Makey Makey running on an ESP8266
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
#include <Wire.h> | |
#define ttp229 (0xAF>>1) | |
uint16_t data_out = 0; | |
uint16_t data1, data2; | |
int count = 0; | |
boolean count2 = false; | |
// https://github.com/witnessmenow/BPLib | |
#include <BPLib.h> | |
#include <SoftwareSerial.h> | |
#define RX_PIN D6 // connect to TXD of module | |
#define TX_PIN D5 // connect to RXD of module (logic level 3.3v!) | |
SoftwareSerial swSer(RX_PIN, TX_PIN, false, 128); | |
char keyLookUp[] = { 'a', 'w', 's', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q' }; | |
int button[16]; | |
int oldata[16]; | |
BPLib *BPMod; | |
void setup() | |
{ | |
Serial.begin(115200); | |
swSer.begin(115200); | |
BPMod = new BPLib(swSer); | |
BPMod->begin(BP_MODE_HID,BP_HID_KEYBOARD); //Begin HID Mode with HID KEYBOARD AS TYPE | |
Wire.begin(); | |
} | |
void loop() | |
{ | |
Wire.requestFrom(ttp229, 2, true); | |
delay(1); | |
while (Wire.available()) | |
{ | |
data1 = Wire.read(); | |
data2 = Wire.read(); | |
data_out = (data1 << 8) | data2; | |
for (int i = 1; i < 17; i++) | |
{ | |
uint16_t contrast = 0x8000; | |
if (data_out & contrast) | |
{ | |
//Serial.println(i); | |
button[count] = i; | |
count++; | |
delay(1); | |
} | |
data_out <<= 1; | |
} | |
if (count2) | |
{ | |
switch (count) | |
{ | |
case 1: | |
if (oldata[0] == button[0]) | |
{ | |
Serial.println(button[0]); | |
BPMod->sendChar(keyLookUp[button[0] -1]); | |
delay(20); | |
} | |
break; | |
case 2: | |
if (oldata[0] == button[0] && oldata[1] == button[1]) | |
{ | |
for (int i = 0; i < 2; i++) | |
{ | |
Serial.print(button[i]); | |
BPMod->sendChar(keyLookUp[button[i] -1]); | |
Serial.print(" "); | |
delay(10); | |
} | |
} | |
break; | |
} | |
} | |
delay(50); | |
for (int i = 0; i < 16; i++) | |
{ | |
oldata[i] = button[i]; | |
} | |
count = 0; | |
count2 = !count2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment