⬆️ ⬇️

Grape multitouch

Stumbled upon an interesting thing called MaKey MaKey.



http://makeymakey.com/



That is what I respect Americans for - it’s for talent to beautifully present and bring to production the simplest thing.

')





I watched the video, I was glad for the guys. But somewhere immediately start to itch. Climbed for rezukami. After 15 minutes (of which five minutes went for a smoke break) this device turned out like this:







UPD> ... after a while. A new video with the practical use of a grape multitouch :-) The source of the soft in C # and the new sketch for Arduin are laid out below.







The implementation is simple to indecency. Only resistors with nominal values ​​of 1-50 Mom are needed (one for each contact). I used resumes for 1 Megohm, as a result of which only touches are trapped. If you put 10Mom and more - it will work at a distance, without contact.



In the sketch I used the CapSense library , which, in fact, does all the work.



Connection diagram:







On the basis of the sample sketched a simple sketch



#include <CapSense.h>



#define SND_PIN 12 // ,



CapSense key1 = CapSense(7, 5); // 1 7- 5-

CapSense key2 = CapSense(7, 4); // 2 7- 4-

CapSense key3 = CapSense(7, 3); // 3 7- 3-



int range = 200; // , ,

byte button; //

int freq; //



void setup()

{

// 1- .

// ,

key1.set_CS_AutocaL_Millis(0xFFFFFFFF);

}



void loop()

{

long total1 = key1.capSense(30);

long total2 = key2.capSense(30);

long total3 = key3.capSense(30);



button = 0;

if (total1 > range) button |= 1;

if (total2 > range) button |= 2;

if (total3 > range) button |= 4;



switch (button) {

case 1: freq = 200; break ;

case 2: freq = 300; break ;

case 3: freq = 400; break ;

case 4: freq = 500; break ;

case 5: freq = 600; break ;

case 6: freq = 700; break ;

case 7: freq = 800; break ;

default : freq = 0;

}



freq? tone(SND_PIN, freq) : noTone(SND_PIN); //

}



* This source code was highlighted with Source Code Highlighter .
#include <CapSense.h>



#define SND_PIN 12 // ,



CapSense key1 = CapSense(7, 5); // 1 7- 5-

CapSense key2 = CapSense(7, 4); // 2 7- 4-

CapSense key3 = CapSense(7, 3); // 3 7- 3-



int range = 200; // , ,

byte button; //

int freq; //



void setup()

{

// 1- .

// ,

key1.set_CS_AutocaL_Millis(0xFFFFFFFF);

}



void loop()

{

long total1 = key1.capSense(30);

long total2 = key2.capSense(30);

long total3 = key3.capSense(30);



button = 0;

if (total1 > range) button |= 1;

if (total2 > range) button |= 2;

if (total3 > range) button |= 4;



switch (button) {

case 1: freq = 200; break ;

case 2: freq = 300; break ;

case 3: freq = 400; break ;

case 4: freq = 500; break ;

case 5: freq = 600; break ;

case 6: freq = 700; break ;

case 7: freq = 800; break ;

default : freq = 0;

}



freq? tone(SND_PIN, freq) : noTone(SND_PIN); //

}



* This source code was highlighted with Source Code Highlighter .




If you flash something like this , the arduin with the grape keys will be in the role of the HID-keyboard (I have not tried it yet). But for this, not every Arduinka is suitable, you need it with an atmega8u2 chip as a USB controller (the new Arduino UNO is right with it). It’s a pity there is nothing suitable at hand, but I wanted to play Bamberman online from the grape keyboard :-) You can, of course, jot down a soft that will read signals from the keypad through the COM port and translate them into keyboard events, but this is no longer then (through the HID is still more interesting).



UPD> Got a working device, stopped itching, relaxed. I read about Maki Maki in more detail - it turns out that it was done just there on the Arduin :-)



UPD> Just squeaking the speaker is not interesting, it would be necessary for the daughter to have fun :-) Maybe the next topic will be about this, if something interesting happens.



UPD> Found an interesting project - Virtual USB keyboard , without using atmega8u2. I'll have to try to pick it up.



UPD> Question to habrovchan - can someone tell the softphone (preferably under Windows or cross-platform) that would read the COM port, receive messages in some format and generate keystroke events? And then I myself do not quickly cry it.



UPD> Urgently ordered Arduin Uno so that the HID-device turned out "out of the box." I hope the delivery will not fail and will be delivered today. Until I play Bamberman, I will not calm down (and since yesterday I haven’t even gone to bed).



UPD> Now 8 grapes are connected, at the same time all eight are processed, but with dips. 5 simultaneous touches work stably. HID is canceled today for delivery only tomorrow will be :-(



UPD> So ... With the help of the tips of the sidekick, I managed to jot down a simple C # softphone. Reads the Arduin COM port, accepts clicks on grapes, emulates keyboard presses. Right now I'll try to pick up all eight grapes and then take a new video. First wrote something in C # :-)



UPD> Source Code (VS2010, C #). I do not rummage in C #, so how it happened - it happened :-) Thank Leonardo so much for the hints, otherwise it wouldn't work. And thanks to the GreenGo Habrayuser for the tip-off on the InputSimulator library.



The software listens to the specified COM port (there are no settings, the name of the port is strictly written in the source code (COM11). This is the port on which Arduin is available. Only 6 keys are involved.



 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using WindowsInput; using System.IO; using System.IO.Ports; namespace WindowsFormsApplication1 { public partial class Form1 : Form { System.IO.Ports.SerialPort newPort; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { newPort = new SerialPort("COM11", 57600, Parity.None, 8, StopBits.One); newPort.Open(); newPort.DataReceived += new SerialDataReceivedEventHandler(GetArduinoBytes); } public void GetArduinoBytes(object sender, SerialDataReceivedEventArgs e) { string data = newPort.ReadExisting(); string [] arr; int key = 0; arr = data.Split('\r'); try { key = Convert.ToInt32(arr[0]); } catch (System.FormatException) { //    } int key1 = key & 1; int key2 = (key >> 1) & 1; int key3 = (key >> 2) & 1; int key4 = (key >> 3) & 1; int key5 = (key >> 4) & 1; int key6 = (key >> 5) & 1; int key7 = (key >> 6) & 1; int key8 = (key >> 7) & 1; if (key1 == 1) WindowsInput.InputSimulator.SimulateKeyDown(VirtualKeyCode.DOWN); else WindowsInput.InputSimulator.SimulateKeyUp(VirtualKeyCode.DOWN); if (key2 == 1) WindowsInput.InputSimulator.SimulateKeyDown(VirtualKeyCode.UP); else WindowsInput.InputSimulator.SimulateKeyUp(VirtualKeyCode.UP); if (key3 == 1) WindowsInput.InputSimulator.SimulateKeyDown(VirtualKeyCode.LEFT); else WindowsInput.InputSimulator.SimulateKeyUp(VirtualKeyCode.LEFT); if (key4 == 1) WindowsInput.InputSimulator.SimulateKeyDown(VirtualKeyCode.RIGHT); else WindowsInput.InputSimulator.SimulateKeyUp(VirtualKeyCode.RIGHT); if (key5 == 1) WindowsInput.InputSimulator.SimulateKeyDown(VirtualKeyCode.SPACE); else WindowsInput.InputSimulator.SimulateKeyUp(VirtualKeyCode.SPACE); if (key6 == 1) WindowsInput.InputSimulator.SimulateKeyDown(VirtualKeyCode.VK_Z); else WindowsInput.InputSimulator.SimulateKeyUp(VirtualKeyCode.VK_Z); } } } 




UPD> And here's a new sketch for Arduin. Playback of the speaker squeak commented out, just pass the state of the keys to the console.



 #include <CapSense.h> #define SND_PIN 12 // ,     CapSense key1 = CapSense(5, 2); //  1  5-  5-  CapSense key2 = CapSense(5, 3); //  2  5-  4-  CapSense key3 = CapSense(5, 4); //  3  5-  3-  CapSense key4 = CapSense(5, 6); //  4  5-  3-  CapSense key5 = CapSense(5, 7); //  5  5-  3-  CapSense key6 = CapSense(5, 8); //  6  5-  3-  CapSense key7 = CapSense(5, 9); //  7  5-  3-  CapSense key8 = CapSense(5, 11); //  8  5-  3-  int range = 100; //  ,   unsigned int button = 0, oldButton = 0; //     int freq; //       byte sense = 30; long total1, total2, total3, total4, total5, total6, total7, total8; void setup() { //key1.set_CS_AutocaL_Millis(0xFFFFFFFF); Serial.begin(57600); //   } void loop() { total1 = key1.capSense(sense); total2 = key2.capSense(sense); total3 = key3.capSense(sense); total4 = key4.capSense(sense); total5 = key5.capSense(sense); total6 = key6.capSense(sense); total7 = key7.capSense(sense); total8 = key8.capSense(sense); button = 0; if (total1 > range) button |= 1; if (total2 > range) button |= 2; if (total3 > range) button |= 4; if (total4 > range) button |= 8; if (total5 > range) button |= 16; if (total6 > range) button |= 32; if (total7 > range) button |= 64; if (total8 > range) button |= 128; if (button != oldButton) { Serial.println(button); oldButton = button; } /* if (button) freq = button * 10 + 200; else freq = 0; if (freq) { Serial.println(freq); tone(SND_PIN, freq); } else noTone(SND_PIN); //     */ } 




UPD> About MakiMaki on TV showed. I was called to participate in the program with this my “grape multitouch”, but had to be abandoned for political reasons :-)



Source: https://habr.com/ru/post/143928/



All Articles