πŸ“œ ⬆️ ⬇️

How I created a magic piano

In the Hackspace robot technology park β€œ Navigator Campus ”, they often receive orders for technical development, one of such small but interesting developments will be discussed in this article.



Once, Artem Kramin (co-founder of free space for Dial in Kazan) addressed us with the idea of ​​the quest project β€œ Room ”. He wanted to bring a certain element of magic into his quest and to modernize the old piano for this. The task was set as follows: when playing the correct melody, the door in the next room should open.

The functionality of the instrument and its sonority should not suffer in the process of modernization, nothing should interfere with the extraction of sound. An important requirement is that a musical instrument should not have changes in its appearance, so that the quest participant would not have guessed anything ahead of time.
')
In the process of thinking born solutions such as:


Practically everyone who was interested in the process of developing a miracle instrument was sure that a microphone was used, but the option with it quickly disappeared, because a person who has never had an affair with a piano can play a melody, which means that the melody cannot be played evenly, plus upset, and using the camera was too expensive and time consuming to implement, and hiding it from the participants would be another problem. In the end, the choice fell on the limit switches.

This is the general scheme of the device:


To install the trailers, I drew and cut a frame for fastening in our laser hackspace on a laser cut.

The process of cutting the version of Google Car


The mount is a single element mounted on the guides inside the piano.


After that I soldered the wires to the limit switches (later it turned out that the red wire could be removed)


Then I bought an EM lock, power supply and power button.
All that I purchased checked for performance.






Then I installed and soldered all the necessary circuit elements, it looks rough, but it has been working for a month and a half without failures.




So here is the device assembly.




The whole scheme of work is this: the system is constantly waiting for the first right key to be pressed, then waiting for the second right note, and so on. In a situation where the quest participant makes a mistake and presses the wrong note, the combination is reset and the β€œcode” must be dialed again, and if the whole melody is played correctly, the lock opens, locking the room door.

Sketch Sources
const int key1 = 4; // const int key2 = 5; // const int key3 = 6; // const int key4 = 7; // const int key5 = 8; // const int key6 = 9; // const int key7 = 10; // const int lock = 12; // int lastKey = 0; //   //   void openLock() { digitalWrite(lock, LOW); delay(10000); closeLock(); } //  void closeLock() { digitalWrite(lock, HIGH); } //    key boolean isKeyPressed(int key) { int what = -1; while(true) { int countPressed = 0; if(digitalRead(key1) == HIGH) { if(lastKey != key1) { countPressed++; what = key1; lastKey = key1; } } if(digitalRead(key2) == HIGH) { if(lastKey != key2) { countPressed++; what = key2; lastKey = key2; } } if(digitalRead(key3) == HIGH) { if(lastKey != key3) { countPressed++; what = key3; lastKey = key3; } } if(digitalRead(key4) == HIGH) { if(lastKey != key4) { countPressed++; what = key4; lastKey = key4; } } if(digitalRead(key5) == HIGH) { if(lastKey != key5) { countPressed++; what = key5; lastKey = key5; } } if(digitalRead(key6) == HIGH) { if(lastKey != key6) { countPressed++; what = key6; lastKey = key6; } } if(digitalRead(key7) == HIGH) { if(lastKey != key7) { countPressed++; what = key7; lastKey = key7; } } if(what != -1) { Serial.print("pressed "); Serial.println(what - 3); if((countPressed == 1) && (key == what)) { break; } if((key != what) || (countPressed >= 1)) { break; } } } if(what == key) { return true; } else { return false; } } void setup() { // pinMode(test,INPUT); Serial.begin(9600); pinMode(key1, INPUT); pinMode(key2, INPUT); pinMode(key3, INPUT); pinMode(key4, INPUT); pinMode(key5, INPUT); pinMode(key6, INPUT); pinMode(key7, INPUT); pinMode(lock, OUTPUT); closeLock(); } //         void loop() { if(isKeyPressed(key2)) { if(isKeyPressed(key3)) { if(isKeyPressed(key6)) { if(isKeyPressed(key2)) { if(isKeyPressed(key4)) { if(isKeyPressed(key6)) { if(isKeyPressed(key1)) { if(isKeyPressed(key7)) { openLock(); } } } } } } } } } 


After all the preparations, the device was installed in the piano, and the lock is fixed in the doorway (in which secret).








Bottom line: Artyom was pleased, but I was interested in doing something unusual.
PS Readers from Kazan, even after reading this article, will be interested in completing the quest, because the magic piano is only a small part of the Room magic.

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


All Articles