# DIY Makey Makey mit einem Arduino Leonardo
## Selbstbau eines MakeyMakey auf der Basis eines **STM32** Boards
![](https://i.imgur.com/0lmUzxb.png)
- [Anleitung](https://www.instructables.com/id/3-Alternative-to-Makey-Makey/) (Materialkosten ca. 5 € mit leitfähiger Knete :-)
(Mirek Hancl, hancl.de, @infchem
![](https://i.imgur.com/aFVBJWm.png)
> Bildquelle: Simone Ferrecchia DIGIJEUNES |
> https://wikifab.org/wiki/DIY_Makey_Makey_with_Arduino_Leonardo
> Lizenz: Creative Commons Attribution
> http://creativecommons.org/licenses/by/3.0/
Ein MakeyMakey ist die einfachste Art, mit Scratch alle möglichen leitfähigen Gegenstände anzusteuern: Obst, Metall, leitfähige Knete .. geradezu berühmt geworden ist das "Bananenklavier" :-)
Mit einem Arduino Leonardo kann man relativ einfach einen MakeyMakey selbst bauen ...
dazu gibt es zahlreiche Anleitungen im Netz:
etwa
https://wikifab.org/wiki/DIY_Makey_Makey_with_Arduino_Leonardo#Schritt_2_-_Program_the_Makey_Makey-like_device
... der Code dazu befindet sich weiter unten ....
***
# Code von Andreas Ohrdorf für die Makerfaire Hannover 17.+18.8.19
Wir machen es ganz einfach:
(Die genaue **Anleitung zur Verkabelung** wird nachgereicht, sie findet sich aber auch in englisch auf der oben erwähnten Seite
https://wikifab.org/wiki/DIY_Makey_Makey_with_Arduino_Leonardo#Schritt_2_-_Program_the_Makey_Makey-like_device
)
// Code von Andreas Ohrdorf von den Lobomaten
// kurzelinks.de/mmleo
// .. für die MakerFaire Hannover
// https://maker-faire.de/maker/coding-und-making-im-unterricht-2/
#include <Keyboard.h>
#include <movingAvg.h>
// Original values were 200 and then 600
const int PressedMaxThreshold = 200;
const int ReleasedMinThreshold = 300;
const byte PinCount = 6;
const byte InputPins[PinCount] = {A0, A1, A2, A3,};
const char KeyCodes[PinCount] = {'a', 'b', 'c', 'D'};
struct TouchInput
{
byte analogPin;
char keycode;
movingAvg filter = movingAvg(20);
boolean wasPressed = false;
};
TouchInput Pins[PinCount];
void setup()
{
Serial.begin(115200);
for (int i = 0; i < PinCount; i++)
{
Pins[i].analogPin = InputPins[i];
Pins[i].keycode = KeyCodes[i];
Pins[i].filter.begin();
}
}
void loop()
{
for (int i = 0; i < PinCount; i++)
{
float currentAverage = Pins[i].filter.reading(analogRead(Pins[i].analogPin));
boolean previousState = Pins[i].wasPressed;
boolean currentState = previousState; // Default if in the dead zone
if (currentAverage < PressedMaxThreshold)
{
currentState = true; // Pressed
}
else if (currentAverage > ReleasedMinThreshold)
{
currentState = false; // Released
}
if (currentState != previousState)
{
if (currentState)
Keyboard.press(Pins[i].keycode);
else
Keyboard.release(Pins[i].keycode);
}
Pins[i].wasPressed = currentState;
}
}
***
DIY Makey Makey with Arduino Leonardo
https://wikifab.org/wiki/DIY_Makey_Makey_with_Arduino_Leonardo#Schritt_2_-_Program_the_Makey_Makey-like_device
...
Here you can download the code to upload on your Arduino board:
https://drive.google.com/file/d/1__jvuINFsJ_YzBHWltmv5_40187U9US6/view
#include <Keyboard.h>
#include <movingAvg.h>
// Original values were 200 and then 600
const int PressedMaxThreshold = 200;
const int ReleasedMinThreshold = 300;
const byte PinCount = 6;
const byte InputPins[PinCount] = {A0, A1, A2, A3, A4, A5};
const char KeyCodes[PinCount] = {'d', 's', 'w', 'a', 'z', 'e'};
struct TouchInput
{
byte analogPin;
char keycode;
movingAvg filter = movingAvg(20);
boolean wasPressed = false;
};
TouchInput Pins[PinCount];
void setup()
{
Serial.begin(115200);
for (int i = 0; i < PinCount; i++)
{
Pins[i].analogPin = InputPins[i];
Pins[i].keycode = KeyCodes[i];
Pins[i].filter.begin();
}
}
void loop()
{
for (int i = 0; i < PinCount; i++)
{
float currentAverage = Pins[i].filter.reading(analogRead(Pins[i].analogPin));
boolean previousState = Pins[i].wasPressed;
boolean currentState = previousState; // Default if in the dead zone
if (currentAverage < PressedMaxThreshold)
{
currentState = true; // Pressed
}
else if (currentAverage > ReleasedMinThreshold)
{
currentState = false; // Released
}
if (currentState != previousState)
{
if (currentState)
Keyboard.press(Pins[i].keycode);
else
Keyboard.release(Pins[i].keycode);
}
Pins[i].wasPressed = currentState;
}
}